- Perl excels at processing strings:
- Input and output is via strings
- Regular expressions are powerful ways of manipulating strings
- Functions such as split manipulate strings powerfully
- Operators such as =~ transform strings easily
- Strings may even be used as array subscripts in associative arrays
- Use print or printf (formatted) to output to
the terminal or to a file. man perlfunc for detailed syntax.
- Concatonating a string means simply to mush different parts
together. The . operator is usually used for this:
print "Dude, it's" . $time . "\n"; (note: how could this be
written more easily without concatonation?)
my $x = $y . $z;
if ($hour > 12) { $ampm="pm"; } else { $ampm="am"; }
- $first='Greg' ;
$last='Newby'; $status{$first . $last} = "faculty"; print $status{'GregNewby'}
- General tip: when you get input to a string, the LF/CR character
often remains. You often want chomp to strip any such
characters from the end of a string.
|