[27579] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 9107 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 30 21:05:49 2006

Date: Thu, 30 Mar 2006 18:05:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 30 Mar 2006     Volume: 10 Number: 9107

Today's topics:
        *flush* (was: Re: Find duplicates in a dat file) <rvtol+news@isolution.nl>
    Re: Find duplicates in a dat file axel@white-eagle.invalid.uk
    Re: Find duplicates in a dat file <eflorac@imaginet.fr>
    Re: Find duplicates in a dat file <someone@example.com>
    Re: Find duplicates in a dat file (Anno Siegel)
    Re: Find duplicates in a dat file <rvtol+news@isolution.nl>
    Re: Find duplicates in a dat file <tadmc@augustmail.com>
    Re: Find duplicates in a dat file axel@white-eagle.invalid.uk
        split()'s pattern argument <jerry.adair@sas.com>
    Re: split()'s pattern argument xhoster@gmail.com
        split()'s regex pattern parameter <jerry.adair@sas.com>
    Re: split()'s regex pattern parameter <rvtol+news@isolution.nl>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 31 Mar 2006 01:36:55 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: *flush* (was: Re: Find duplicates in a dat file)
Message-Id: <e0i14d.1rk.1@news.isolution.nl>

Dr.Ruud schreef:
> Emmanuel Florac schreef:

>> (what's happening if
>> for any reason $| is -1 ?)
> 
>   perl -le 'for ($|) {$_=-1; print; --$_; print; $_=999; print; --$_;
> print}'

More fun:

#!/usr/bin/perl
use strict; use warnings;

{ local ($,, $\) = ("\t", "\n");

  for ($|)
  {
    print( 1, $_ = -1 );
    print( 2, --$_ );
    print( 3, $_ = 999 );
    print( 4, --$_ );
    print( 5, ++$_ );
    chop;       # line 13
    print( 6, $_ );
    s//9/;
    print( 7, $_ );
  }
}


Variant:

#!/usr/bin/perl
use strict; use warnings;

for ($|) {
  while (my $c = <DATA>) {
    eval $c; print "$.\t$_\n";
  }
}
__DATA__
$_ = -1
--$_
$_ = 999
--$_
++$_
chop
s//9/

-- 
Affijn, Ruud

"Gewoon is een tijger."


------------------------------

Date: Thu, 30 Mar 2006 20:47:33 GMT
From: axel@white-eagle.invalid.uk
Subject: Re: Find duplicates in a dat file
Message-Id: <FtXWf.45099$wl.1310@text.news.blueyonder.co.uk>

Tami@des.com wrote:
> I have run most of what has been said in the replies BUT I still cannot get to work.
 
> Some of the help scripts just sit there and do nothing.
 
> I get "premature end of script headers" in most of the scripts that have been suggested.
 
Ah... that makes rather a difference.

Try putting the following line near the beginning of the scripts which
create that error, just after 'use warnings' and 'use strict':

$|++;

Axel


------------------------------

Date: Thu, 30 Mar 2006 23:24:45 +0200
From: Emmanuel Florac <eflorac@imaginet.fr>
Subject: Re: Find duplicates in a dat file
Message-Id: <pan.2006.03.30.21.24.44.910189@imaginet.fr>

Le Thu, 30 Mar 2006 20:47:33 +0000, axel a écrit :

> 
> $|++;

Well, actually 

$| = 1; 

is way better. Sure it doesn't look that nerdish, but it's both more
readable, it's less error prone and bug prone (what's happening if for any
reason $| is -1 ?), and it's better for perl reputation ( my perl code
ain't line noise pollution, my perl code ain't gonna die... said AC/DC )

-- 
Ne pas savoir de quoi on parle est un avantage dont il ne faut pas
abuser. 
R.Debray



------------------------------

Date: Thu, 30 Mar 2006 21:53:14 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Find duplicates in a dat file
Message-Id: <erYWf.10077$Ph4.558@edtnps90>

Anno Siegel wrote:
> 
> The problem with concatenating all files together is that it tells
> you whether there are duplicate mail addresses, but not which users
> the duplicates belong to.  With the files in @ARGV, the $ARGV variable
> can be used to capture at least the file names the duplicates come from.
> Untested:
> 
>     my %seen;
>     push $seen->{ $1}, $ARGV if /(.*@.*)/;
           ????????????

push() needs an actual array as the first argument.  Have you declared the
scalar $seen before using it there?


>     while ( my ( $addr, $files) = each %seen ) {
>         print "$addr found in files @$files\n" if @$files > 1;
>     }

John
-- 
use Perl;
program
fulfillment


------------------------------

Date: 30 Mar 2006 22:02:57 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Find duplicates in a dat file
Message-Id: <4932sgFmkp9rU1@news.dfncis.de>

John W. Krahn <krahnj@telus.net> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> > 
> > The problem with concatenating all files together is that it tells
> > you whether there are duplicate mail addresses, but not which users
> > the duplicates belong to.  With the files in @ARGV, the $ARGV variable
> > can be used to capture at least the file names the duplicates come from.
> > Untested:
> > 
> >     my %seen;
> >     push $seen->{ $1}, $ARGV if /(.*@.*)/;
>            ????????????
> 
> push() needs an actual array as the first argument.  Have you declared the
> scalar $seen before using it there?

No, "$seen->{ $1}" is clearly nonsense there.  Thanks for the vigilance.
It should have been

    push @{ $seen{ $1} }, $ARGV if /(.*@.*)/;

Untested again :)

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


------------------------------

Date: Fri, 31 Mar 2006 00:05:21 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Find duplicates in a dat file
Message-Id: <e0hron.1ao.1@news.isolution.nl>

Emmanuel Florac schreef:
> axel:

>>     $|++;
>
> Well, actually
>
>     $| = 1;
>
> is way better.

I prefer

    ++$|;

because it stands out more (for me).


> Sure it doesn't look that nerdish, but it's both more
> readable, it's less error prone and bug prone (what's happening if
> for any reason $| is -1 ?)

  perl -le 'for ($|) {$_=-1; print; --$_; print; $_=999; print; --$_;
print}'

-- 
Affijn, Ruud

"Gewoon is een tijger."



------------------------------

Date: Thu, 30 Mar 2006 16:23:09 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Find duplicates in a dat file
Message-Id: <slrne2omid.9pm.tadmc@magna.augustmail.com>


[ please set your newsreader to keep the line lengths to no more that 
  70-72 characters.

  Thank you.
]


Tami@des.com <Tami@des.com> wrote:

> I get "premature end of script headers" in most of the scripts 
> that have been suggested.


That is because Perl is not only for CGI programming, so many
of the answers illustrate the essential Perl programming stuff
that they are trying to get across, but don't do all the required
CGI-cruft stuff, like emitting headers.

You should get your CGI progrmas running *from the command line* first, 
then move them to a web server after they've been mostly debugged.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Thu, 30 Mar 2006 22:31:35 GMT
From: axel@white-eagle.invalid.uk
Subject: Re: Find duplicates in a dat file
Message-Id: <b%YWf.45172$wl.11165@text.news.blueyonder.co.uk>

Emmanuel Florac <eflorac@imaginet.fr> wrote:
> Le Thu, 30 Mar 2006 20:47:33 +0000, axel a écrit :
 
>> $|++;
 
> Well, actually 
 
> $| = 1; 
 
> is way better. Sure it doesn't look that nerdish, but it's both more
> readable, it's less error prone and bug prone (what's happening if for any
> reason $| is -1 ?), and it's better for perl reputation ( my perl code
> ain't line noise pollution, my perl code ain't gonna die... said AC/DC )

True.

I forgot to mention that a content type must be the very first
thing to be output as this can cause the very same error message.
A CGI tutorial should be consulted for details.

Axel
 


------------------------------

Date: Thu, 30 Mar 2006 14:55:35 -0500
From: "Jerry Adair" <jerry.adair@sas.com>
Subject: split()'s pattern argument
Message-Id: <e0hd3o$u65$1@foggy.unx.sas.com>

Hello-

'Encountering something weird (well weird to me), 'couldn't find it in the
FAQ:

when attempting to call split() with a value to "split on" that is stored in
a scalar, I get behavior other than what I expected.  The Camel book says to
just put it inside match delimiters, but that doesn't help the cause.  Thus:

@line = split( /$separator/ );

doesn't do what I thought it would, as if $separator was replaced with:

@line = split( " " );

The problem I am encountering is when I try to access the list produced by 
the split (with the scalar), the first list value is null if the very first 
"token" it encounters matches the value contained in the scalar.  So for 
simplicity, I set $separator = ' '; then when using this scalar in the call 
to split(), it just so happens that the first line of data begins with a 
space, followed by two "words" that are separated by whitespace.  So the 
list that I get back from split() has 3 elements in it: a null, the first 
word and the second word.  However, with the simple string example (I know 
that split will parse a string as a pattern even when not given as a 
pattern) I get the correct results, which are simply the first word and the 
second word, thus the list I get back has only 2 elements in it, as it 
should.

I don't know why I am experiencing this behavior. I'm probably missing 
something simple, but I thought I'd ask anyway.

Thank you in advance.

Jerry






------------------------------

Date: 30 Mar 2006 20:44:57 GMT
From: xhoster@gmail.com
Subject: Re: split()'s pattern argument
Message-Id: <20060330155423.825$5c@newsreader.com>

"Jerry Adair" <jerry.adair@sas.com> wrote:
> Hello-
>
> 'Encountering something weird (well weird to me), 'couldn't find it in
> the FAQ:
>
> when attempting to call split() with a value to "split on" that is stored
> in a scalar, I get behavior other than what I expected.  The Camel book
> says to just put it inside match delimiters, but that doesn't help the
> cause.  Thus:
>
> @line = split( /$separator/ );
>
> doesn't do what I thought it would, as if $separator was replaced with:
>
> @line = split( " " );

split " " is a special case, and does not do the same thing as split / /.
A variable which contains a space will give you the split / / behavior, not
the special-case split " " behavior.

This was discussed to death here a couple of weeks ago.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


------------------------------

Date: Thu, 30 Mar 2006 14:27:28 -0500
From: "Jerry Adair" <jerry.adair@sas.com>
Subject: split()'s regex pattern parameter
Message-Id: <e0hbf0$tbk$1@foggy.unx.sas.com>

Hello-

'Encountering something weird (well weird to me), 'couldn't find it in the 
FAQ:

when attempting to call split() with a value to "split on" that is stored in 
a scalar, I get behavior other than what I expected.  The Camel book says to 
just put it inside match delimiters, but that doesn't help the cause.  Thus:

@line = split( /$separator/ );

doesn't do what I thought it would, as if $separator was replaced with:

@line = split( " " );

The problem I am encountering is when I try to access the list produced by 
the split (with the scalar), the first list value is null.  However, with 
the simple string example (I know that split will parse a string as a 
pattern even when not given as a pattern) I get the correct results, which 
is a non-null list (for a given non-null line of data).

I don't know why this pattern won't work in regex parser, I was surprised. 
I'm probably missing something simple, but I thought I'd ask anyway.

Thank you in advance.

Jerry 




------------------------------

Date: Thu, 30 Mar 2006 22:58:09 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: split()'s regex pattern parameter
Message-Id: <e0ho7n.1u8.1@news.isolution.nl>

Jerry Adair schreef:

> when attempting to call split() with a value to "split on" that is
> stored in a scalar, I get behavior other than what I expected.  The
> Camel book says to just put it inside match delimiters, but that
> doesn't help the cause.  Thus: 
> 
> @line = split( /$separator/ );

Where are the examples of the value of $separator?


> doesn't do what I thought it would, as if $separator was replaced
> with: 
> 
> @line = split( " " );
> 
> The problem I am encountering is when I try to access the list
> produced by the split (with the scalar), the first list value is
> null.

Does the PATTERN contain parentheses?  See perldoc -f split. 


Also: <quote> A "split" on "/\s+/" is
like a "split(' ')" except that any leading whitespace produces
a null first field.  A "split" with no arguments really does a
"split(' ', $_)" internally. </quote>


> However, with the simple string example (I know that split
> will parse a string as a pattern even when not given as a pattern) I
> get the correct results, which is a non-null list (for a given
> non-null line of data). 

If your PATTERN is a single space, then you have a special case.


> I don't know why this pattern won't work in regex parser, I was
> surprised. I'm probably missing something simple, but I thought I'd
> ask anyway. 

Did you try $separator = qr/PATTERN/ ?

-- 
Affijn, Ruud

"Gewoon is een tijger."


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 9107
***************************************


home help back first fref pref prev next nref lref last post