in reply to Need to search for a string in a file
You needn't pull the whole file into memory just to search for one line.
The caret character,(^), means start of the line in a regex. Read perlre, these meta-characters is the second subject covered.
You can match save and exit the loop in one statement.
The caret character,(^), means start of the line in a regex. Read perlre, these meta-characters is the second subject covered.
You can match save and exit the loop in one statement.
sub get_file_from_log(){ my $log_name=shift; open(my $log_file, "<", $log_name); my $file_name; while (<logFile>){ last if ($file_name) = /^Generated filename\s*=\s*(.+)$/; } return $file_name; }
print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Need to search for a string in a file
by jwkrahn (Abbot) on Oct 20, 2011 at 20:38 UTC | |
Re^2: Need to search for a string in a file
by akrrs7 (Acolyte) on Oct 20, 2011 at 11:51 UTC | |
by aartist (Pilgrim) on Oct 20, 2011 at 14:19 UTC | |
Re^2: Need to search for a string in a file
by anneli (Pilgrim) on Oct 20, 2011 at 21:25 UTC | |
by aaron_baugher (Curate) on Oct 20, 2011 at 22:29 UTC | |
by anneli (Pilgrim) on Oct 20, 2011 at 23:07 UTC | |
by aaron_baugher (Curate) on Oct 21, 2011 at 18:36 UTC |
In Section
Seekers of Perl Wisdom