Line 23: printf is not the operator to use ( Perl is not C ). Use print with a trailing newline where appropriate(or, with a recent version of Perl, say)
You'll find this ( sorta' ) works:
for (@ID,@ISIN,@SYMBOL, "\n",) { print "$_:"; } ...
That's a really ugly hack and produces many lines containing only a single colon.
Nonetheless, for part one, see printf and compare to print.
For part two, writing a coherent set of suggestions about the other problems (unnecessary use of arrays which you then route thru a foreach; failing to give your series of "ifs" an escape route (better, perhaps, an if, two elsifs and an else); etc.; would take more time than I have just now. [<update> Besides, muba did a fine job on most of it while I was still fiddling. </update>] Sorry, but perhaps you can infer (or read docs) how this works:
#!/usr/bin/perl use 5.014; sub getValue { my ($value, $name); # $name is a throwaway; why? $_ = shift; ( $name, $value ) = split(/:/); $value =~ s/\s//g; return $value; } print "ID SYMBOL ISIN\n"; while (<DATA>) { my ($ID,$ISIN,$SYMBOL); if ($_ =~ m/ID:/) { $ID = getValue($_); $ID = $ID . ":"; # append colon removed by split chomp $ID; print $ID; } elsif ($_ =~ m/Symbol:/) { $SYMBOL = getValue($_); chomp $SYMBOL; $SYMBOL .= ":"; # alternate method to append colon print $SYMBOL; } elsif ($_ =~ m/ISIN:/) { $ISIN = getValue($_); chomp $ISIN; print $ISIN ."\n"; } else { next; } } __DATA__ Deleted; see careless OP's request in node below and +, as msgd to me: "Sorry for bothering you sir. But could you please change the data on +node : http://www. perlmonks.org/? displaytype= displaycode; node_id= +976512 to : http://www. perlmonks.org/? displaytype= displaycode; nod +e_id=991009 , appreciate it! !prod data"
output:
ID SYMBOL ISIN QYQ:LUP2L100OHM:SE0004017929 R1M:TLS2K50OHM:SE0004018539 QNF:MINILONGOMXAO:SE0003990183 QX8:ALF2K160OHM:SE0004017440 NC0:BOL2K170OHM:SE0003842137 NEV:NOK2K90OHM:SE0003843069
OP or OP's management seems to believe one can make things disappear from the internet.
Wrong. Can you spell "cache" or "waybackmachine?"
OP also seems to think I have some hold over kenosis, as evidenced by this message (verbatim), also received by me:
"kamchez says Re Re: matching strings into array from txtfile and printing on same linekenosis, could you please change all of the "data" to dummy data as follows, the reason is that the current data is important production data that shouldn't be online (my fault) and that my employer wants it removed asap "
In reply to Re: matching strings into array from txtfile and printing on same line
by ww
in thread matching strings into array from txtfile and printing on same line
by kamchez
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |