Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Possibly useful perl script to filter lines in one file out of another.

Reply
Thread Tools

Possibly useful perl script to filter lines in one file out of another.

 
 
Mart van de Wege
Guest
Posts: n/a
 
      08-24-2009
http://www.velocityreviews.com/forums/(E-Mail Removed) writes:

> On Sun, 23 Aug 2009 22:22:19 -0500, Tad J McClellan <(E-Mail Removed)> wrote:

<snip>
>>
>>Show me a program where you pass an undefined filehandle to read
>>and it dies...
>>

> use strict;
> use warnings;
>
> my ($buf,$length) = ('',5);
>
> # Invoke error #2, FATAL error on read
> my $fh;
>
> {
> local $!;
> my $status = eval { read ($fh, $buf, $length) };
> $@ =~ s/\s+$//;
> if ($@ || (!$status && $!)) {
> print "Error in read: ". ($@ ? $@ : $! ). "\n";
> }
> }
>
> print "More code ...\n";
>
> __END__
> c:\temp>perl ss.pl
> Error in read: Can't use an undefined value as a symbol reference at ss.pl line
> 13.


Your program is not dying on an undefined filehandle. It is dying on an
undefined scalar. This is not the same.

Mart

--
"We will need a longer wall when the revolution comes."
--- AJS, quoting an uncertain source.
 
Reply With Quote
 
 
 
 
Nathan Keel
Guest
Posts: n/a
 
      08-24-2009
(E-Mail Removed) wrote:

>
> In reality, you should never need to check the return value from
> open(). If you can't program to that spec, you haven't been paid to
> program. -sln


To say one should never need to check the return value (rather than
arguing about die'ing), just shows how unqualified you are as an
alleged programmer. No one is suggesting to not check other things,
but checking that a file opened is sometimes useful or needed. If you
don't recognize or admit that, then you are a complete failure at
simple programming logic.
 
Reply With Quote
 
 
 
 
sln@netherlands.com
Guest
Posts: n/a
 
      08-24-2009
On Mon, 24 Aug 2009 08:41:06 +0200, Mart van de Wege <(E-Mail Removed)> wrote:

>(E-Mail Removed) writes:
>
>> On Sun, 23 Aug 2009 22:22:19 -0500, Tad J McClellan <(E-Mail Removed)> wrote:

><snip>
>>>
>>>Show me a program where you pass an undefined filehandle to read
>>>and it dies...
>>>

>> use strict;
>> use warnings;
>>
>> my ($buf,$length) = ('',5);
>>
>> # Invoke error #2, FATAL error on read
>> my $fh;
>>
>> {
>> local $!;
>> my $status = eval { read ($fh, $buf, $length) };
>> $@ =~ s/\s+$//;
>> if ($@ || (!$status && $!)) {
>> print "Error in read: ". ($@ ? $@ : $! ). "\n";
>> }
>> }
>>
>> print "More code ...\n";
>>
>> __END__
>> c:\temp>perl ss.pl
>> Error in read: Can't use an undefined value as a symbol reference at ss.pl line
>> 13.

>
>Your program is not dying on an undefined filehandle. It is dying on an
>undefined scalar. This is not the same.
>
>Mart


Your wrong, its die'ing in runtime, function call 'read()'
-sln
 
Reply With Quote
 
sln@netherlands.com
Guest
Posts: n/a
 
      08-24-2009
On Sun, 23 Aug 2009 23:46:06 -0700, Nathan Keel <(E-Mail Removed)> wrote:

>(E-Mail Removed) wrote:
>
>>
>> In reality, you should never need to check the return value from
>> open(). If you can't program to that spec, you haven't been paid to
>> program. -sln

>
>To say one should never need to check the return value (rather than
>arguing about die'ing), just shows how unqualified you are as an
>alleged programmer. No one is suggesting to not check other things,
>but checking that a file opened is sometimes useful or needed. If you
>don't recognize or admit that, then you are a complete failure at
>simple programming logic.


Its too simple in that logic.
-sln

 
Reply With Quote
 
sln@netherlands.com
Guest
Posts: n/a
 
      08-24-2009
On Mon, 24 Aug 2009 00:06:09 -0700, (E-Mail Removed) wrote:

>On Mon, 24 Aug 2009 08:41:06 +0200, Mart van de Wege <(E-Mail Removed)> wrote:
>
>>(E-Mail Removed) writes:
>>
>>> On Sun, 23 Aug 2009 22:22:19 -0500, Tad J McClellan <(E-Mail Removed)> wrote:

>><snip>
>>>>
>>>>Show me a program where you pass an undefined filehandle to read
>>>>and it dies...
>>>>
>>> use strict;
>>> use warnings;
>>>
>>> my ($buf,$length) = ('',5);
>>>
>>> # Invoke error #2, FATAL error on read
>>> my $fh;
>>>
>>> {
>>> local $!;
>>> my $status = eval { read ($fh, $buf, $length) };
>>> $@ =~ s/\s+$//;
>>> if ($@ || (!$status && $!)) {
>>> print "Error in read: ". ($@ ? $@ : $! ). "\n";
>>> }
>>> }
>>>
>>> print "More code ...\n";
>>>
>>> __END__
>>> c:\temp>perl ss.pl
>>> Error in read: Can't use an undefined value as a symbol reference at ss.pl line
>>> 13.

>>
>>Your program is not dying on an undefined filehandle. It is dying on an
>>undefined scalar. This is not the same.
>>
>>Mart

>
>Your wrong, its die'ing in runtime, function call 'read()'
>-sln


Furthermore, failed filehandle opens are valid and don't emit this error when
used in a read.
Go figure.. Just when you think you know it all
-sln
 
Reply With Quote
 
Mart van de Wege
Guest
Posts: n/a
 
      08-24-2009
(E-Mail Removed) writes:

> On Mon, 24 Aug 2009 08:41:06 +0200, Mart van de Wege <(E-Mail Removed)> wrote:
>
>>(E-Mail Removed) writes:
>>
>>> On Sun, 23 Aug 2009 22:22:19 -0500, Tad J McClellan <(E-Mail Removed)> wrote:

>><snip>
>>>>
>>>>Show me a program where you pass an undefined filehandle to read
>>>>and it dies...
>>>>
>>> use strict;
>>> use warnings;
>>>
>>> my ($buf,$length) = ('',5);
>>>
>>> # Invoke error #2, FATAL error on read
>>> my $fh;
>>>
>>> {
>>> local $!;
>>> my $status = eval { read ($fh, $buf, $length) };
>>> $@ =~ s/\s+$//;
>>> if ($@ || (!$status && $!)) {
>>> print "Error in read: ". ($@ ? $@ : $! ). "\n";
>>> }
>>> }
>>>
>>> print "More code ...\n";
>>>
>>> __END__
>>> c:\temp>perl ss.pl
>>> Error in read: Can't use an undefined value as a symbol reference at ss.pl line
>>> 13.

>>
>>Your program is not dying on an undefined filehandle. It is dying on an
>>undefined scalar. This is not the same.
>>
>>Mart

>
> Your wrong, its die'ing in runtime, function call 'read()'
> -sln


I'm not.

It's dying on the read, yes, but *not* on an undefined filehandle.

If you can't distinguish your referents from your references, you have
no business programming.

Mart

--
"We will need a longer wall when the revolution comes."
--- AJS, quoting an uncertain source.
 
Reply With Quote
 
sln@netherlands.com
Guest
Posts: n/a
 
      08-24-2009
On Mon, 24 Aug 2009 09:38:19 +0200, Mart van de Wege <(E-Mail Removed)> wrote:

>(E-Mail Removed) writes:
>
>> On Mon, 24 Aug 2009 08:41:06 +0200, Mart van de Wege <(E-Mail Removed)> wrote:
>>
>>>(E-Mail Removed) writes:
>>>
>>>> On Sun, 23 Aug 2009 22:22:19 -0500, Tad J McClellan <(E-Mail Removed)> wrote:
>>><snip>
>>>>>
>>>>>Show me a program where you pass an undefined filehandle to read
>>>>>and it dies...
>>>>>
>>>> use strict;
>>>> use warnings;
>>>>
>>>> my ($buf,$length) = ('',5);
>>>>
>>>> # Invoke error #2, FATAL error on read
>>>> my $fh;
>>>>
>>>> {
>>>> local $!;
>>>> my $status = eval { read ($fh, $buf, $length) };
>>>> $@ =~ s/\s+$//;
>>>> if ($@ || (!$status && $!)) {
>>>> print "Error in read: ". ($@ ? $@ : $! ). "\n";
>>>> }
>>>> }
>>>>
>>>> print "More code ...\n";
>>>>
>>>> __END__
>>>> c:\temp>perl ss.pl
>>>> Error in read: Can't use an undefined value as a symbol reference at ss.pl line
>>>> 13.
>>>
>>>Your program is not dying on an undefined filehandle. It is dying on an
>>>undefined scalar. This is not the same.
>>>
>>>Mart

>>
>> Your wrong, its die'ing in runtime, function call 'read()'
>> -sln

>
>I'm not.
>
>It's dying on the read, yes, but *not* on an undefined filehandle.
>
>If you can't distinguish your referents from your references, you have
>no business programming.
>
>Mart


I guess a filehandle has to be defined or its not a filehandle,
which is really a reference to GLOB which is undefined.
So the point is that thing passed to the slot called the FILEHANDLE in
the parameter list for read is undefined.

Good call, thanks for schooling me.
Anything else to point out before the real issue, IT DIES man??
Any business on that issue? Re-read the text, stop slurping crap
out of your navel!

-sln
 
Reply With Quote
 
Mart van de Wege
Guest
Posts: n/a
 
      08-24-2009
(E-Mail Removed) writes:

> On Mon, 24 Aug 2009 09:38:19 +0200, Mart van de Wege <(E-Mail Removed)> wrote:
>
>>(E-Mail Removed) writes:
>>
>>> On Mon, 24 Aug 2009 08:41:06 +0200, Mart van de Wege <(E-Mail Removed)> wrote:
>>>
>>>>(E-Mail Removed) writes:
>>>>
>>>>> On Sun, 23 Aug 2009 22:22:19 -0500, Tad J McClellan <(E-Mail Removed)> wrote:
>>>><snip>
>>>>>>
>>>>>>Show me a program where you pass an undefined filehandle to read
>>>>>>and it dies...
>>>>>>
>>>>> use strict;
>>>>> use warnings;
>>>>>
>>>>> my ($buf,$length) = ('',5);
>>>>>
>>>>> # Invoke error #2, FATAL error on read
>>>>> my $fh;
>>>>>
>>>>> {
>>>>> local $!;
>>>>> my $status = eval { read ($fh, $buf, $length) };
>>>>> $@ =~ s/\s+$//;
>>>>> if ($@ || (!$status && $!)) {
>>>>> print "Error in read: ". ($@ ? $@ : $! ). "\n";
>>>>> }
>>>>> }
>>>>>
>>>>> print "More code ...\n";
>>>>>
>>>>> __END__
>>>>> c:\temp>perl ss.pl
>>>>> Error in read: Can't use an undefined value as a symbol reference at ss.pl line
>>>>> 13.
>>>>
>>>>Your program is not dying on an undefined filehandle. It is dying on an
>>>>undefined scalar. This is not the same.
>>>>
>>>>Mart
>>>
>>> Your wrong, its die'ing in runtime, function call 'read()'
>>> -sln

>>
>>I'm not.
>>
>>It's dying on the read, yes, but *not* on an undefined filehandle.
>>
>>If you can't distinguish your referents from your references, you have
>>no business programming.
>>
>>Mart

>
> I guess a filehandle has to be defined or its not a filehandle,
> which is really a reference to GLOB which is undefined.
> So the point is that thing passed to the slot called the FILEHANDLE in
> the parameter list for read is undefined.
>

Irrelevant. You're passing a scalar to read(), not a filehandle.

> Good call, thanks for schooling me.


So just admit you're wrong and shut up.

> Anything else to point out before the real issue, IT DIES man??


Sod off you whiner. Tad said that Perl doesn't die on an undefined
filehandle. Your example doesn't refute that. The real issue is that you
are *wrong*, and trying to avoid admitting that.

> Any business on that issue? Re-read the text, stop slurping crap
> out of your navel!


Learn to program before you open your mouth about the subject.

Mart
--
"We will need a longer wall when the revolution comes."
--- AJS, quoting an uncertain source.
 
Reply With Quote
 
Jrgen Exner
Guest
Posts: n/a
 
      08-24-2009
Nathan Keel <(E-Mail Removed)> wrote:
>(E-Mail Removed) wrote:
>
>>
>> In reality, you should never need to check the return value from
>> open(). If you can't program to that spec, you haven't been paid to
>> program. -sln

>
>To say one should never need to check the return value (rather than
>arguing about die'ing), just shows how unqualified you are as an
>alleged programmer. No one is suggesting to not check other things,
>but checking that a file opened is sometimes useful or needed. If you
>don't recognize or admit that, then you are a complete failure at
>simple programming logic.


Took you a surprisingly long tme to recognize that. Everyone else has
filtered Mr. Sln aka Robic0 a loooooong time ago.

jue
 
Reply With Quote
 
Nathan Keel
Guest
Posts: n/a
 
      08-24-2009
Jrgen Exner wrote:

> Took you a surprisingly long tme to recognize that. Everyone else has
> filtered Mr. Sln aka Robic0 a loooooong time ago.
>
> jue


No, I've always realized it, but I don't filter people out. I'm able to
just ignore them when I want. I usually ignore him anymore.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Some interactive Python tutorials on basic stats, possibly useful for teaching Raj Python 0 02-14-2011 02:53 PM
"rec.photo.digital.txt" Filter File Posted Online (for newsreadersthat can import a list of e-mail addresses to filter out) SMS 斯蒂文• 夏 Digital Photography 2 11-25-2007 11:00 AM
How to filter out lines from a variable that has multi-lines? mike Perl Misc 3 10-02-2007 12:08 AM
possibly someday useful ?? google search MsOsWin@anon.com XML 0 12-10-2004 09:12 PM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM



Advertisments