Re: csv flat file
I've already seen many examples, so I shall not touch on foreach. The Map function could do the work too assuming memory is not a problem. However I am not too sure if I got the following short cut correct :- open FILE, 'data.txt' or die "$!\n"; print (map "InsertYourText $_",); close FILE; Thanks - Original Message - From: "bc" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, January 24, 2002 5:54 AM Subject: csv flat file hello i have a flat file (csv) [it has about 114 rows] i want to put the word "insert " in front of each row, how it the "for each" writtin? in other words, in perl, how do i do a for each row insert the word "insert ", then it comes out of the "for each" loop thingy...? _ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: csv flat file
Yes, the '.' operator is the concatenation operator. Another useful related operator is the .= operator, which automatically adds the right side of the expression to the end of the left side. $foo = "Hello "; $bar = "World!"; $foo .= $bar; #$foo is now "Hello World!" But in this case you needed the string at the beginning of the line. -Original Message- From: bc [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 24, 2002 10:56 AM To: Timothy Johnson; 'Jon Molin ' Subject: Re: csv flat file ah, i see your point, and is that a dot ( . ) right before the $line; in the foreach command? does that join the text: "insert " to the string: $line? - Original Message - From: "Timothy Johnson" <[EMAIL PROTECTED]> To: "'Jon Molin '" <[EMAIL PROTECTED]>; "'bc '" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Thursday, January 24, 2002 11:30 AM Subject: RE: csv flat file > > What I do when I want to do something to each line of a file is break it up > into an array with one line per element of the array. That way I can put in > conditions that let me decide which lines I want to do it to. For example: > > open(INFILE,"infile.csv"); > @infile = ; > close INFILE; > > foreach $line(@infile){ >$line = "insert ".$line; > } > > open(OUTFILE,">infile.csv"); > print OUTFILE @infile; > > > > -Original Message- > From: Jon Molin > To: bc > Cc: [EMAIL PROTECTED] > Sent: 1/24/02 5:44 AM > Subject: Re: csv flat file > > bc wrote: > > > > hello > > > > i have a flat file (csv) [it has about 114 rows] > > > > i want to put the word "insert " in front of each row, > > > > how it the "for each" writtin? in other words, in perl, how do i do a > for each row insert the word "insert ", then it comes out of the "for > each" loop thingy...? > > perl -pi.bak -e 's/^/insert /' filename > > would do it (remove .bak if you don't want a backup) > > /jon > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- -- > This email may contain confidential and privileged > material for the sole use of the intended recipient. > If you are not the intended recipient, please contact > the sender and delete all copies. > This email may contain confidential and privileged material for the sole use of the intended recipient. If you are not the intended recipient, please contact the sender and delete all copies. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: csv flat file
good point. -Original Message- From: Russ Foster To: [EMAIL PROTECTED] Sent: 1/24/02 8:37 AM Subject: RE: csv flat file Depending on the size of the file, you may not want to read the whole thing into memory first. So... open(OUTFILE,">outfile.csv") ; open(INFILE,"mailto:[EMAIL PROTECTED]] Sent: Thursday, January 24, 2002 10:30 AM To: 'Jon Molin '; 'bc ' Cc: [EMAIL PROTECTED] Subject: RE: csv flat file What I do when I want to do something to each line of a file is break it up into an array with one line per element of the array. That way I can put in conditions that let me decide which lines I want to do it to. For example: open(INFILE,"infile.csv"); @infile = ; close INFILE; foreach $line(@infile){ $line = "insert ".$line; } open(OUTFILE,">infile.csv"); print OUTFILE @infile; -Original Message- From: Jon Molin To: bc Cc: [EMAIL PROTECTED] Sent: 1/24/02 5:44 AM Subject: Re: csv flat file bc wrote: > > hello > > i have a flat file (csv) [it has about 114 rows] > > i want to put the word "insert " in front of each row, > > how it the "for each" writtin? in other words, in perl, how do i do a for each row insert the word "insert ", then it comes out of the "for each" loop thingy...? perl -pi.bak -e 's/^/insert /' filename would do it (remove .bak if you don't want a backup) /jon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This email may contain confidential and privileged material for the sole use of the intended recipient. If you are not the intended recipient, please contact the sender and delete all copies. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This email may contain confidential and privileged material for the sole use of the intended recipient. If you are not the intended recipient, please contact the sender and delete all copies. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: csv flat file
Depending on the size of the file, you may not want to read the whole thing into memory first. So... open(OUTFILE,">outfile.csv") ; open(INFILE,"mailto:[EMAIL PROTECTED]] Sent: Thursday, January 24, 2002 10:30 AM To: 'Jon Molin '; 'bc ' Cc: [EMAIL PROTECTED] Subject: RE: csv flat file What I do when I want to do something to each line of a file is break it up into an array with one line per element of the array. That way I can put in conditions that let me decide which lines I want to do it to. For example: open(INFILE,"infile.csv"); @infile = ; close INFILE; foreach $line(@infile){ $line = "insert ".$line; } open(OUTFILE,">infile.csv"); print OUTFILE @infile; -Original Message- From: Jon Molin To: bc Cc: [EMAIL PROTECTED] Sent: 1/24/02 5:44 AM Subject: Re: csv flat file bc wrote: > > hello > > i have a flat file (csv) [it has about 114 rows] > > i want to put the word "insert " in front of each row, > > how it the "for each" writtin? in other words, in perl, how do i do a for each row insert the word "insert ", then it comes out of the "for each" loop thingy...? perl -pi.bak -e 's/^/insert /' filename would do it (remove .bak if you don't want a backup) /jon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This email may contain confidential and privileged material for the sole use of the intended recipient. If you are not the intended recipient, please contact the sender and delete all copies. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: csv flat file
What I do when I want to do something to each line of a file is break it up into an array with one line per element of the array. That way I can put in conditions that let me decide which lines I want to do it to. For example: open(INFILE,"infile.csv"); @infile = ; close INFILE; foreach $line(@infile){ $line = "insert ".$line; } open(OUTFILE,">infile.csv"); print OUTFILE @infile; -Original Message- From: Jon Molin To: bc Cc: [EMAIL PROTECTED] Sent: 1/24/02 5:44 AM Subject: Re: csv flat file bc wrote: > > hello > > i have a flat file (csv) [it has about 114 rows] > > i want to put the word "insert " in front of each row, > > how it the "for each" writtin? in other words, in perl, how do i do a for each row insert the word "insert ", then it comes out of the "for each" loop thingy...? perl -pi.bak -e 's/^/insert /' filename would do it (remove .bak if you don't want a backup) /jon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This email may contain confidential and privileged material for the sole use of the intended recipient. If you are not the intended recipient, please contact the sender and delete all copies. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: csv flat file
bc wrote: > > hello > > i have a flat file (csv) [it has about 114 rows] > > i want to put the word "insert " in front of each row, > > how it the "for each" writtin? in other words, in perl, how do i do a for each row >insert the word "insert ", then it comes out of the "for each" loop thingy...? perl -pi.bak -e 's/^/insert /' filename would do it (remove .bak if you don't want a backup) /jon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
csv flat file
hello i have a flat file (csv) [it has about 114 rows] i want to put the word "insert " in front of each row, how it the "for each" writtin? in other words, in perl, how do i do a for each row insert the word "insert ", then it comes out of the "for each" loop thingy...?