When you use a back-ticked command line to assign a string to a perl variable, the string includes the final line-feed character that was printed at the end by the shell command. So if you plan to use the string as a file name in an open statement, you need to "chomp" it:
my $date =`/bin/date +'%m%d%y'`;
chomp $date;
my $LOG = "log.$date";
# another way to do that is to use perl internals instead of a sub-she
+ll:
{
my ($d,$m,$y)=(localtime)[3..5];
my $perldate = sprintf "%02d%02d%02d", $m+1, $d, $y-100;
die "This should never happen: $perldate != $date"
if $perldate ne $date;
}
As for your question 3, I'm not quite sure about your intention, but I think the best way to start is by using a regex match and capture:
while (<HANDLE>) {
next unless ( /FREEZING media id (.*)/ );
print "I am FREEZING $1\n";
}
(BTW, when using date strings in file names, I like to arrange them as "%y%m%d", so they sort nicely.)
update: Forgot to mention: when using a regex match in the while loop as shown above, you don't need to open a pipeline that runs the data through a separate "grep" process -- perl does the grep for you, by ignoring the lines that don't match the regex.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.