open(OUT_FILE,">output.txt"); # Open for output (create) open(OUT_FILE,">>output.txt"); # Open for output (append, or create)
open(MY_FILE,"some.dat");
while( <MY_FILE> )
{
}
open(OUT_FILE,">output.txt"); # Open for output (create) print OUT_FILE "Hi There!\n";Specifying File to open for input on the command line
open(MYFILE,$ARGV[0]) || die "can't open $ARGV[0]: $!\n"
require "find.pl";
&find('../some_directory');
sub wanted {
#The "wanted" sub-rtn is called once for each file found, the file name
# is passed in the $_ variable.
}
$string1 = "Hi " . "There!";Testing if a string contains a sub string
if ($a_string =~ m/Elephant/)
To do a case insensitive search use- if ($a_string =~ m/Elephant/i)
$a_string =~ s/Peking/Bejing/g;
$string =~ tr/a-z/A-Z/; # convert to lower case $string =~ tr/A-Z/a-z/; # convert to upper case
$tmp_ptr = index($current_line,"something");
$a_bit_of_string = substr($some_string,$start_pos,$length);
$a_string= "name=john"; ($tmp1, $tmp2) = split(/=/,$a_string); #$tmp1 now has "name" in it, $tmp2 has "john"
$different_strings{$a_string} = $different_strings{$a_string} + 1;
foreach (@some_assoc_array)
{ print $_; } # the value is in $_ by default
foreach $variable_with_key (keys(%some_assoc_array))
{ print $variable_with_key; }
@tmp_assoc_array_1 = keys(%some_assoc_array); @tmp_assoc_array_2 = sort @tmp_assoc_array_2; foreach (@tmp_assoc_array_2) ( print $_; }
if ($some_assoc_arry{$the_key} eq "" )
{ print "key not in array"; }
if ( $string eq "Hi There" ) if ( "A" gr "B" ) if ( $num == 10) if ( $num != 10) if ( $num > 10) if ($x > 208 && $x < 275 && $y > 64 && $y < 78 ) # && is AND, || is OR
#Define the Header Line format STDOUT_TOP= Name Address Num ----------- ---------------------- ----- . #Dot marks end of format #Define the detail Line format STDOUT = @<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<@###### $name, $address, $num, . #Dot marks end of format write; #Write the detail Line to STDOUT # Notes: < String Justify Left, > String Justify Right, | String Centered, # Numeric,
&MY_SUB("John",1); #Call the sub-rtn, and pass it two literals
sub MY_SUB {
$name = $_[0];
$number = $_[1];
}
exec "pwd";Reading whats in STDIN
if ($ENV{CONTENT_LENGTH} ne "") #** Is there anything in "Standard In" ?
{
read(STDIN, $save_string, $ENV{CONTENT_LENGTH}); # Yes- put it in $save_string
}
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
= localtime(time);
$mon = $mon +1;
$date_string = sprintf("%02d-%02d-%02d", $mon, $mday, $year);
print "Date is ", $date_string; # prints mm-dd-yy