issue wit sysopen
------_=_NextPart_001_01CBF755.D6BD62B5
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Hi All
I have following simple code :
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
use warnings;
sysopen(DATA,"list1.txt",O_RDWR|O_TRUNC);
[at] array1=3D<DATA>;
foreach $i ( [at] array1){
$i =3D~ s/d|b/G/ig;
print DATA $i;
}
close DATA;
-------------------
It is failing with following error : Argument "O_VVW^C" isn't numeric in
sysopen at sysopen.pl line 3.
I am not able to find the cause of this issue. Could anybody let me know
, where I am wrong ?
Thanks
Sunita
------_=_NextPart_001_01CBF755.D6BD62B5--
Re: issue wit sysopen
Hi Sunita.
A few comments on your code.
On Sunday 10 Apr 2011 11:03:51 Sunita Rani Pradhan wrote:
> Hi All
>
>
>
> I have following simple code :
>
>
>
> ===================
>
> use warnings;
>
Add "use strict;".
>
>
> sysopen(DATA,"list1.txt",O_RDWR|O_TRUNC);
1. Don't use typeglob filehandles - use lexical ones.
2. Check for a successful return or throw an exception.
3. You need to import the module with the constants.
<CODE>
use Fcntl;
sysopen(my $data_fh, "list1.txt", O_RDWR|O_TRUNC)
or die "Cannot open - $!";
</CODE>
>
>
>
> [at] array1=<DATA>;
>
1. Declare the variable using my.
2. Perhaps you don't want to slurp the entire file.
>
>
>
>
> foreach $i ( [at] array1){
>
foreach my $i - and it should not be really called "$i", but rather $line or
whatever.
>
>
> $i =~ s/d|b/G/ig;
>
Thsi should be :
$line =~ s/[db]/G/ig;
> print DATA $i;
>
> }
>
>
>
> close DATA;
>
Seems like you're trying to modify the file in place. The problem is that
you've read it all and are trying to modify it. The best way would probably be
to write this from the command line:
perl -pi.bak -e 's/[db]/G/ig' list1.txt # Untested
For more information see:
http://perl-begin.org/tutorials/bad-elements/
Regards,
Shlomi Fish
--
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
Apple Inc. is Evil - http://www.shlomifish.org/open-source/anti/apple/
*shlomif:* hack, hack, hack ; save ; make ; make test; commit. And start over.
*mrjink:*hack, hack, hack; save; make; swear; fix typos; save; make; make
test; swear some more; hack some more; save; make; make test; cheer; commit.
*meep:* hack, make, test, segfault, oh noes, revert to previous revision
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: issue wit sysopen
--20cf3002588c6f0bf504a08c616c
Content-Type: text/plain; charset=ISO-8859-1
On Apr 10, 2011 4:05 AM, "Sunita Rani Pradhan" <Sunita.Pradhan [at] altair.com>
wrote:
>
> sysopen(DATA,"list1.txt",O_RDWR|O_TRUNC);
>
Why not just use open with +< ? I've never seen the benefit of sysopen
unless you're working with a stream. Also, I don't know those options are
compatible with each other.
> It is failing with following error : Argument "O_VVW^C" isn't numeric in
> sysopen at sysopen.pl line 3.
>
IIRC the options are numeric (binary?) values that get added up. Maybe that
'VVW' is the result. If I'm right, this nonsense result is because the
options don't work together.
>
>
> I am not able to find the cause of this issue. Could anybody let me know
> , where I am wrong ?
>
>
>
>
>
> Thanks
>
> Sunita
>
--20cf3002588c6f0bf504a08c616c--
Re: issue wit sysopen
shawn wilson wrote:
> On Apr 10, 2011 4:05 AM, "Sunita Rani Pradhan"<Sunita.Pradhan [at] altair.com>
> wrote:
>>
>> sysopen(DATA,"list1.txt",O_RDWR|O_TRUNC);
>>
>
> Why not just use open with +< ? I've never seen the benefit of sysopen
> unless you're working with a stream. Also, I don't know those options are
> compatible with each other.
>
>> It is failing with following error : Argument "O_VVW^C" isn't numeric in
>> sysopen at sysopen.pl line 3.
>>
>
> IIRC the options are numeric (binary?) values that get added up.
Values that get bitwise ANDed together.
> Maybe that 'VVW' is the result.
Yes, if the OP doesn't use strict and warnings then O_RDWR and O_TRUNC
are treated by perl as text strings.
> If I'm right, this nonsense result is because the
> options don't work together.
According to:
perldoc perlopentut
They should work together, but only if the file already exists.
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: issue wit sysopen
Shlomi Fish wrote:
>
> On Sunday 10 Apr 2011 11:03:51 Sunita Rani Pradhan wrote:
>>
>> $i =~ s/d|b/G/ig;
>
> Thsi should be :
>
> $line =~ s/[db]/G/ig;
Or possibly even:
$line =~ tr/dbDB/G/;
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: issue wit sysopen
On 11-04-10 06:06 AM, John W. Krahn wrote:
> Values that get bitwise ANDed together.
That would be "ORed together". ;)
--
Just my 0.00000002 million dollars worth,
Shawn
Confusion is the first step of understanding.
Programming is as much about organization and communication
as it is about coding.
The secret to great software: Fail early & often.
Eliminate software piracy: use only FLOSS.
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/