in reply to new to perl
There may be a clever regex to do this, but here is a simple way a beginner can understand.
#!/usr/bin/perl use warnings; use strict; open (my $fh, "< test.txt") or die "$!\n"; #input file open (my $oh, "> $0-out.txt") or die "$!\n"; #output file my $script = '/home/whoever/bin/myscript.pl'; while (<$fh>){ my $string = $_; # strip off trailing <br> and anything after it $string =~ s/<br>.*$//; #strip whitespace at end in case space preceded the <br> $string =~ s/\s+$//; ## split on space my @words = split / /, $string; #print join "\n",@words,"\n"; my $lastword = $words[-1]; print $oh "$script $lastword\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: new to perl
by kroz (Initiate) on Jul 16, 2012 at 06:06 UTC |