how to append a string to next line in perl
Posted
by tprayush
on Stack Overflow
See other posts from Stack Overflow
or by tprayush
Published on 2010-04-09T16:32:56Z
Indexed on
2010/04/09
16:43 UTC
Read the original article
Hit count: 237
perl
hi all , i have a requirement like this.. this just a sample script...
$ cat test.sh
#!/bin/bash
perl -e '
open(IN,"addrss");
open(out,">>addrss");
@newval;
while (<IN>)
{
@col_val=split(/:/);
if ($.==1)
{
for($i=0;$i<=$#col_val;$i++)
{
print("Enter value for $col_val[$i] : ");
chop($newval[$i]=<STDIN>);
}
$str=join(":");
$_="$str"
print OUT;
}
else
{
exit 0;
}
}
close(IN);
close(OUT);
' when i run this scipt...
$ ./test.sh
Enter value for NAME : abc
Enter value for ADDRESS : asff35
Enter value for STATE : XYZ
Enter value for CITY : EIDHFF
Enter value for CONTACT
: 234656758
$ cat addrss
NAME:ADDRESS:STATE:CITY:CONTACT
abc:asff35:XYZ:EIDHFF:234656758
when ran it second time
$ cat addrss
NAME:ADDRESS:STATE:CITY:CONTACT
abc:asff35:XYZ:EIDHFF:234656758ioret:56fgdh:ghdgh:afdfg:987643221 ## it is appended in the same line...
i want it to be added to the next line.....
NOTE: i want to do this by explitly using the filehandles in perl....and not with redirection operators in shell.
please help me!!!
© Stack Overflow or respective owner