Thank you all for taking the time to help me out! It's truly amazing how many ways there are to do something ;) I've learned a lot by reading your replies and I've cleaned up the code a little and tweaked it with the input I got from each of you. here it goes;
use strict; use warnings; use File::Basename; use Text::ParseWords; if ($#ARGV == 0) { open my $file, "<", $ARGV[0] or die "Couldn't open file '$ARGV +[0]': $! \nDid you specify a valid file?"; my ($ID,$ISIN,$SYMBOL); while (<$file>) { if ($_ =~ m/ID:/) { $ID = getValue($_); } if ($_ =~ m/Symbol:/) { $SYMBOL = getValue($_); } if ($_ =~ m/ISIN:/) { $ISIN = getValue($_); print "$ID:$ISIN:$SYMBOL\n"; } } } else { print "You need to specify an input file \n"; print "Usage : ".basename($0)." difffile.txt \n"; exit; } sub getValue { $_ =~ s/\s+//g; my ($name, $value) = split(/:/); chomp($value); return $value; }
please let me know if there are any more improvements that can be done to make it more "clean" and "proper" according to "proper coding standards" ;9 Thank you all !!
Output from diff_file, running :nt!!QYP:SE0001234567:LUP2L80OHM NGA:SE0001234567:SHB2K260OHM NJQ:SE0001234567:TRE2K70OHM NH0:SE0001234567:SKF3A190OHM NEY:SE0001234567:NOK3A70OHM QUA:SE0001234567:MINILONGLUPFO QPC:SE0001234567:MINISHRTOMXOO QP3:SE0001234567:MINISHRTOMXFO QU9:SE0001234567:MINILONGLUPEO P3B:SE0001234567:SWM2K240OHM P0N:SE0001234567:ASS3A160OHM NGF:SE0001234567:SHB3A260OHM R1B:SE0001234567:SKF2K210OHM QP8:SE0001234567:MINISHRTOMXKO R1K:SE0001234567:TEL3A123OHM P34:SE0001234567:SWE2K140OHM NAS:SE0001234567:ASS2K180OHM NC3:SE0001234567:BOL3A150OHM NDD:SE0001234567:HM2L280OHM NCX:SE0001234567:ERI3A120OHM P2D:SE0001234567:OXS3A1300OHM QNA:SE0001234567:MINILONGABBCO NGV:SE0001234567:SKF2K190OHM QPE:SE0001234567:MINISHRTOMXQO QU7:SE0001234567:MINILONGLUPCO
In reply to Re: matching strings into array from txtfile and printing on same line
by kamchez
in thread matching strings into array from txtfile and printing on same line
by kamchez
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |