Help with script How to prepend 2 lines instead of 1
Using the script below I need to add a second line with the following
text:
"STAGEHDR|Barcoded"
#!perl
use strict;
use warnings;
my $file = 'path/to/Access.csv';
my $newline = "ENTHDR|1|3.0";
{
local [at] ARGV = ($file);
local $^I = '.bac';
while(<>){
if ($. == 1) {
print "$newline$/";
}
else {
print;
}
}
}
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Help with script How to prepend 2 lines instead of 1
Hi Steve,
On Thursday 20 Jan 2011 21:10:39 steve1040 wrote:
> Using the script below I need to add a second line with the following
> text:
> "STAGEHDR|Barcoded"
>
> #!perl
> use strict;
> use warnings;
> my $file = 'path/to/Access.csv';
> my $newline = "ENTHDR|1|3.0";
> {
> local [at] ARGV = ($file);
> local $^I = '.bac';
> while(<>){
Please avoid such games in any half-serious code. While they are useful from
the command line, they won't work properly within a larger code. See my
response to your earlier post with a proper way to do that and some other
pointers.
Regards,
Shlomi Fish
--
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
Optimising Code for Speed - http://shlom.in/optimise
Chuck Norris can make the statement "This statement is false" a true one.
Please reply to list if it's a mailing list post - http://shlom.in/reply .
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Help with script How to prepend 2 lines instead of 1
On 20/01/2011 19:10, steve1040 wrote:
>
> Using the script below I need to add a second line with the following
> text:
> "STAGEHDR|Barcoded"
>
> #!perl
> use strict;
> use warnings;
> my $file = 'path/to/Access.csv';
> my $newline = "ENTHDR|1|3.0";
> {
> local [at] ARGV = ($file);
> local $^I = '.bac';
> while(<>){
> if ($. == 1) {
> print "$newline$/";
> }
> else {
> print;
> }
> }
> }
Hi Steve
You seem to have ignored the help you were offered when you last posted
this problem. The code you have here (apart from the misgivings that
Shlomi has expressed) will /replace/ the first line of the input file
with the given string. Is that what you want, or do you need to add
(prepend) them as you said previously? You have already been shown code
that will do the latter; do you need a different solution?
- Rob
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/