in reply to How to get a value from a file and save in another file
How about
print("LA-1-00 LA-2-01 LA-03-2\n");
Sorry, but I don't see the pattern between your input and output. Did you mean to print out all those starting with LA-? If so, you missed LA-03-02. The following prints all the tokens starting with LA-
open(FILE, "< $filename") or die("Can't open input file: $!\n"); my $text = do { local $/; <FILE> }; close(FILE); print(join(' ', grep { /^LA-/ } split(/\s+/, $text)), "\n");
Update: Maybe LA-03-2 and LA-03-02 are considered duplicates, and you're trying to remove duplicates? If so, the following code should help:
open(FILE, "< $filename") or die("Can't open input file: $!\n"); my $text = do { local $/; <FILE> }; close(FILE); my %seen; print(join(' ', grep { if (/LA-(\d+)-(\d+)/) { my $key = "LA-" . ($1+0) . "-" . ($2+0); $seen{$key}++ ? 0 : 1; } else { 0 } } split(/\s+/, $text)), "\n");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to get a value from a file and save in another file
by Anonymous Monk on Apr 27, 2005 at 17:34 UTC | |
by ikegami (Patriarch) on Apr 27, 2005 at 18:13 UTC |