[30993] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2238 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 26 21:09:45 2009

Date: Thu, 26 Feb 2009 18:09:10 -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, 26 Feb 2009     Volume: 11 Number: 2238

Today's topics:
    Re: Email Purge Again <tod@asgweb.net>
    Re: Forcing list context on <$fh> <tadmc@seesig.invalid>
    Re: Forcing list context on <$fh> <smallpond@juno.com>
    Re: Forcing list context on <$fh> <hjp-usenet2@hjp.at>
    Re: Forcing list context on <$fh> <rvtol+usenet@xs4all.nl>
    Re: Forcing list context on <$fh> <glennj@ncf.ca>
    Re: Forcing list context on <$fh> <jimsgibson@gmail.com>
    Re: Forcing list context on <$fh> <tadmc@seesig.invalid>
    Re: Forcing list context on <$fh> <Alexander.Farber@gmail.com>
    Re: Forcing list context on <$fh> <tadmc@seesig.invalid>
    Re: Forcing list context on <$fh> <ben@morrow.me.uk>
    Re: how do I print the name and value of a scalar <joost@zeekat.nl>
    Re: Net::SSH2 scp_put not working! <schaitan@gmail.com>
    Re: Net::SSH2 scp_put not working! <zentara@highstream.net>
    Re: Net::SSH2 scp_put not working! <schaitan@gmail.com>
    Re: perl implicit loop switch <schaitan@gmail.com>
    Re: perl implicit loop switch <tadmc@seesig.invalid>
    Re: very simple file stitching problem (Heinrich Mislik)
    Re: very simple file stitching problem <jurgenex@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 26 Feb 2009 14:58:29 -0800 (PST)
From: perl <tod@asgweb.net>
Subject: Re: Email Purge Again
Message-Id: <a69ea735-e8f3-4ad7-889f-d3753ebfc7eb@s38g2000prg.googlegroups.com>

Ok.. i guess it WAS working (big homer DOH!). i didn't post the rest
of the code because it didn't seem relevant. using bit's a pieces of
all the fine people that responded i figured it out. thanks to all.
below is finished code.
sub purge
{
my $list2 = "$userpath/files/$list";
my %emails;
open(my $USERS, '<', $list2)
or error("Open 1 failed $list2 $!");
while (<$USERS>) {
       chomp if defined;
       next if /^\s*$/;
# do a check here maybe and a "next" if not a valid email
#address.
       $emails{lc $_} = 1 if ! exists $emails{lc $_};
       #%emails = map { chomp; $_, 1 } <$USERS>;
        }

close($USERS) or warn $!;

while( my ($key,$val) = each %emails) {
        #print "$key = $val\n";
  $newemails .= "$key\n";

}
#print "$_\n" for sort keys %emails;


open(my $USERS, '>', $list2)
or error("Open 2 failed $list2 $!");
print $USERS $newemails;
close($USERS) or warn $!;

&success("$list has been purged of duplicates");
}



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

Date: Thu, 26 Feb 2009 06:45:52 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Forcing list context on <$fh>
Message-Id: <slrngqd3o0.ohi.tadmc@tadmc30.sbcglobal.net>

A. Farber <Alexander.Farber@gmail.com> wrote:

> So I have a ref to array which contains
> either lines from the uploaded CSV file or
> just 1 line 


The 2nd case is not a "line" since it does not have a newline in it...


> constructed from the web form:
>
>         my $input = $fh ? [ <$fh> ] :


>                 $QUERY->param('last'),
>                 $QUERY->param('first'),
>                 $QUERY->param('pass'),
>                 $QUERY->param('user'),
>                 $QUERY->param('company'),
>                 $QUERY->param('city'),


If you put the params into a hash then you can use a "hash slice"
to get the values you want in one go:


    my %Q = $QUERY->Vars;

    sprintf ... , @Q{ qw/ last first pass user company city / };


>                 ($QUERY->param('company') =~ /^mycompany$/i ? '' :
> 'ext-'),


A test for equality should *look like* a test for equality:

   lc($Q{company}) eq 'mycompany' ? '' : 'ext-';


BTW, there are *two* strings that will match /^mycompany$/
(so it isn't really an equality test...).

Do you know what the two possible matching strings are?



> My problem above is that [ <$fh> ] seems
                                     ^^^^^
> to be evaluated in a scalar context and


Find out what context it is in for sure rather than guessing:

    sub context {
        if ( wantarray )
            { warn "list\n" }
        else
            { warn "scalar\n" }
    }
    
    my $input = $fh ? [ context() ] : ...

That shows that the <$fh> _is_ in list context.


> I get just 1 line instead of all.
>
> Is there a nice way to force list context on it?


There is no way to "force" list context like there is for scalar context.

To get a list context, you use it in a place where a list is expected,
such as inside of an anonymous array constructor.

The source of your problem must be somewhere else...


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Thu, 26 Feb 2009 08:07:13 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: Forcing list context on <$fh>
Message-Id: <02b39fdc-2623-4180-b938-ee878e02f76b@r29g2000vbp.googlegroups.com>

On Feb 26, 5:25 am, "A. Farber" <Alexander.Far...@gmail.com> wrote:

> My problem above is that [ <$fh> ] seems
> to be evaluated in a scalar context and
> I get just 1 line instead of all.
>

perl -e 'open FH,"<wbtest.pl"; $r= FH ? [ <FH> ] : []; print $#
$r,"\n"'
180

works fine


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

Date: Thu, 26 Feb 2009 17:42:39 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Forcing list context on <$fh>
Message-Id: <slrngqdhk0.7ku.hjp-usenet2@hrunkner.hjp.at>

On 2009-02-26 12:45, Tad J McClellan <tadmc@seesig.invalid> wrote:
> A. Farber <Alexander.Farber@gmail.com> wrote:
>
>>                 ($QUERY->param('company') =~ /^mycompany$/i ? '' : 'ext-'),
>
>
> A test for equality should *look like* a test for equality:
>
>    lc($Q{company}) eq 'mycompany' ? '' : 'ext-';
>
>
> BTW, there are *two* strings that will match /^mycompany$/
> (so it isn't really an equality test...).

And there are 1024 strings which will match /^mycompany$/i, which will
make it even less of an equality test :-).

	hp


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

Date: Thu, 26 Feb 2009 18:04:48 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: Forcing list context on <$fh>
Message-Id: <49a6cbb0$0$199$e4fe514c@news.xs4all.nl>

Peter J. Holzer wrote:
> Tad J McClellan:
>> A. Farber:

>>>                 ($QUERY->param('company') =~ /^mycompany$/i ? '' : 'ext-'),
>>
>> A test for equality should *look like* a test for equality:
>>
>>    lc($Q{company}) eq 'mycompany' ? '' : 'ext-';
>>
>>
>> BTW, there are *two* strings that will match /^mycompany$/
>> (so it isn't really an equality test...).
> 
> And there are 1024 strings which will match /^mycompany$/i, which will
> make it even less of an equality test :-).

LOL. At least 1024.

-- 
Ruud (maybe more for certain locales)


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

Date: 26 Feb 2009 19:56:38 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: Forcing list context on <$fh>
Message-Id: <slrngqdsvn.6sq.glennj@smeagol.ncf.ca>

At 2009-02-26 07:45AM, "Tad J McClellan" wrote:
>  BTW, there are *two* strings that will match /^mycompany$/
>  (so it isn't really an equality test...).
>  
>  Do you know what the two possible matching strings are?

Maybe I haven't had enough coffee today, but I don't know.  
Please share.

-- 
Glenn Jackman
    Write a wise saying and your name will live forever. -- Anonymous


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

Date: Thu, 26 Feb 2009 12:23:48 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Forcing list context on <$fh>
Message-Id: <260220091223481054%jimsgibson@gmail.com>

In article <slrngqdsvn.6sq.glennj@smeagol.ncf.ca>, Glenn Jackman
<glennj@ncf.ca> wrote:

> At 2009-02-26 07:45AM, "Tad J McClellan" wrote:
> >  BTW, there are *two* strings that will match /^mycompany$/
> >  (so it isn't really an equality test...).
> >  
> >  Do you know what the two possible matching strings are?
> 
> Maybe I haven't had enough coffee today, but I don't know.  
> Please share.

Perhaps "mycompany" and "mycompany\n" (on certain platforms).

-- 
Jim Gibson


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

Date: Thu, 26 Feb 2009 14:15:22 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Forcing list context on <$fh>
Message-Id: <slrngqdu2q.7jd.tadmc@tadmc30.sbcglobal.net>

Glenn Jackman <glennj@ncf.ca> wrote:
> At 2009-02-26 07:45AM, "Tad J McClellan" wrote:
>>  BTW, there are *two* strings that will match /^mycompany$/
>>  (so it isn't really an equality test...).
>>  
>>  Do you know what the two possible matching strings are?
>
> Maybe I haven't had enough coffee today, but I don't know.  
> Please share.


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

$_ = "mycompany\n";
print "matched\n" if /^mycompany$/;

$_ = "mycompany";
print "matched\n" if /^mycompany$/;
-----------------------



-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Thu, 26 Feb 2009 13:56:49 -0800 (PST)
From: "A. Farber" <Alexander.Farber@gmail.com>
Subject: Re: Forcing list context on <$fh>
Message-Id: <4a1ac748-ac22-4b0b-85fd-44ad5840bb8e@q9g2000yqc.googlegroups.com>

Awesome comments, thank you.

The original problem was in fact
not the list/scalar context,
but that my regex didn't match because of \x0d

(uploaded Lotus Notes CSV file in DOS format,
but the script itself runs on Linux)


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

Date: Thu, 26 Feb 2009 18:30:31 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Forcing list context on <$fh>
Message-Id: <slrngqed17.9ui.tadmc@tadmc30.sbcglobal.net>

Jim Gibson <jimsgibson@gmail.com> wrote:
> In article <slrngqdsvn.6sq.glennj@smeagol.ncf.ca>, Glenn Jackman
><glennj@ncf.ca> wrote:
>
>> At 2009-02-26 07:45AM, "Tad J McClellan" wrote:
>> >  BTW, there are *two* strings that will match /^mycompany$/
>> >  (so it isn't really an equality test...).
>> >  
>> >  Do you know what the two possible matching strings are?
>> 
>> Maybe I haven't had enough coffee today, but I don't know.  
>> Please share.
>
> Perhaps "mycompany" and "mycompany\n" (on certain platforms).


On what platforms is that not true?

I thought that perl's IO layer normalized line endings, so that that
should be true on ALL platforms.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Fri, 27 Feb 2009 00:56:45 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Forcing list context on <$fh>
Message-Id: <dbqj76-u6o1.ln1@osiris.mauzo.dyndns.org>


Quoth Tad J McClellan <tadmc@seesig.invalid>:
> Jim Gibson <jimsgibson@gmail.com> wrote:
> > In article <slrngqdsvn.6sq.glennj@smeagol.ncf.ca>, Glenn Jackman
> ><glennj@ncf.ca> wrote:
> >
> >> At 2009-02-26 07:45AM, "Tad J McClellan" wrote:
> >> >  BTW, there are *two* strings that will match /^mycompany$/
> >> >  (so it isn't really an equality test...).
> >> >  
> >> >  Do you know what the two possible matching strings are?
> >> 
> >> Maybe I haven't had enough coffee today, but I don't know.  
> >> Please share.
> >
> > Perhaps "mycompany" and "mycompany\n" (on certain platforms).
> 
> On what platforms is that not true?
> 
> I thought that perl's IO layer normalized line endings, so that that
> should be true on ALL platforms.

IO is irrelevant here. If you have a Perl string containing
"mycompany\n" it will match /^mycompany$/, regardless of how it ended up
with those contents.

Of course, if you read a line from an ordinary text file on Win32 with a
binmoded filehandle, the string returned will be "mycompany\r\n" and
will not match, but that's a completely different question :).

Ben



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

Date: Thu, 26 Feb 2009 15:50:15 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: how do I print the name and value of a scalar
Message-Id: <877i3djlqw.fsf@zeekat.nl>

cartercc <cartercc@gmail.com> writes:

> I might add that in Lisp I can do this without a problem, by printing
> the symbol and then the value of the symbol. I ought to be able to do
> this easily in Perl, but I can't. I'm willing to take the hit for my
> confusion, or my ignorance.

You can only do that in (Common Lisp) with special variables, not with
lexicals. You can do the same in perl if you're willing to use globals
instead of lexicals. The reasons for this and the associated problems
when using that approach are the same too.

(setq val 'special)
(let ((val 'lexical)) 
     (symbol-value 'val))

-- 
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/


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

Date: Thu, 26 Feb 2009 03:38:39 -0800 (PST)
From: Krishna Chaitanya <schaitan@gmail.com>
Subject: Re: Net::SSH2 scp_put not working!
Message-Id: <c5ff1bc8-a021-4d5a-9a75-e0d87cd1312e@r3g2000vbp.googlegroups.com>

> > =A0 =A0 =A0 =A0 print $chan2 "uname -a\n";
> > =A0 =A0 =A0 =A0 print "LINE : $_" while <$chan2>;
>
> Do you get any output here? I would expect that if you've set
> nonblocking mode and it's trying to block that both the print and the <>
> would immediately fail with EAGAIN as well, and you'd get no output. Is
> this not the case?

No, it successfully prints the uname. No EGAIN errors here if I set
blocking(0). And this succeeds every time on my setup.

>
> I don't know. Can you turn on some sort of debug trace, or use tcpdump,
> to see what's actually happening? You will of course need to know more
> about the ssh protocol that I do to make sense of it... :)
>
> Since you're only executing a single command on your Channel, have you
> tried using ->exec instead of ->shell? Messing around with talking to a
> remote shell seems worth avoiding if you can.
>
> Ben

I'd posted in 1 of the posts above my findings from a tcpdump
session.....after which Tim Greer had advised to go back to the basics
instead of examining the gory details of the tcp output. :) So it
kinda got stopped at that. I'm actually quite new to these protocols.
And regarding exec, in this example it will suit me because I'm
running a single command.....in the production program, there will be
many. That's why I had used shell.


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

Date: Thu, 26 Feb 2009 08:20:40 -0500
From: zentara <zentara@highstream.net>
Subject: Re: Net::SSH2 scp_put not working!
Message-Id: <4h5dq4pcqio3fdm9tkhfloomanjp9b7a3k@4ax.com>

On Thu, 26 Feb 2009 01:37:42 -0800 (PST), Krishna Chaitanya
<schaitan@gmail.com> wrote:

>I understood what you said. Maybe I'm not able to communicate my
>concern in the right manner...my program structure is this:

If you havn't yet, look at
http://perlmonks.org/?node=621761

Also, I can't find the nodes, but I also seem to remember problems
with Net::SSH2 and Perl 5.10 (if that is what you are using)
So googling for "Net::SSH2  Perl 5.10  patch" might be helpful.

zentara


-- 
I'm not really a human, but I play one on earth.
http://www.zentara.net/~zentaran/My_Petition_to_the_Great_Cosmic_Conciousness.html 


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

Date: Thu, 26 Feb 2009 05:39:12 -0800 (PST)
From: Krishna Chaitanya <schaitan@gmail.com>
Subject: Re: Net::SSH2 scp_put not working!
Message-Id: <11c8392a-3c8b-45e5-b2d5-3f9859613db3@r28g2000vbp.googlegroups.com>

> If you havn't yet, look athttp://perlmonks.org/?node=3D621761

Yep, I'd read this many days back...that's what gave me the idea of
blocking(0) in the first place :D
I wonder what u235sentinel did (in the above-mentioned posting on
perlmonks) when (s)he succeeded in hitting a couple hundred of boxes
over the network using Net::SSH2. I can't even hit one....without
using blocking(0) I mean.

>
> Also, I can't find the nodes, but I also seem to remember problems
> with Net::SSH2 and Perl 5.10 (if that is what you are using)
> So googling for "Net::SSH2 =A0Perl 5.10 =A0patch" might be helpful.
>

The customer has Perl 5.8.8 so that's going to be my version for a
while. Thanks!


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

Date: Thu, 26 Feb 2009 03:51:00 -0800 (PST)
From: Krishna Chaitanya <schaitan@gmail.com>
Subject: Re: perl implicit loop switch
Message-Id: <ba1d8f13-1691-431e-8a9d-211814701b56@r34g2000vbp.googlegroups.com>

Check out the special variable "$."

This should work:

perl -wne '/(\S+)\s+(\S+)/;print "$. $2\n";' e.dat


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

Date: Thu, 26 Feb 2009 06:56:00 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: perl implicit loop switch
Message-Id: <slrngqd4b0.ohi.tadmc@tadmc30.sbcglobal.net>

alexxx.magni@gmail.com <alexxx.magni@gmail.com> wrote:
><disclaimer: I'm not an expert at all in oneliners>
>
> ... yet I sometimes use them to process datafiles.
>
> And I often find it useful to use the -n switch to extract data, one
> line at a time.
> But what I'm really missing is the possibility to have an incremental
> variable reminding me of which line I'm processing, e.g.:
>
> perl -wne 'my $i=0;/(\S+)\s+(\S+)/;print "$i $2\n";$i++' e.dat
>
> of course it doesnt work, but I'd like to have a way for $i to be
> incremented - there is a hope of accomplishing this?


see the $. variable in "perldoc perlvar":

    perl -wne '/(\S+)\s+(\S+)/;print "$. $2\n"' e.dat 

Try inserting a line like:

    foobar

(or any other line that will fail to match your pattern) into e.dat 
somewhere besides the 1st line, and see if you like its output...

 ... then apply this rule:

   You should never use the dollar-digit variables unless you have
   first ensured that the match *succeeded*.


    perl -wne 'print "$. $2\n" if /(\S+)\s+(\S+)/' e.dat
or
    perl -wlne 'print "$. $2" if /(\S+)\s+(\S+)/' e.dat


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: 26 Feb 2009 12:26:41 GMT
From: Heinrich.Mislik@univie.ac.at (Heinrich Mislik)
Subject: Re: very simple file stitching problem
Message-Id: <49a68a81$0$11094$3b214f66@usenet.univie.ac.at>

In article <ehbbq4lnkded19a8le08lp83hc5udtn4aa@4ax.com>, jurgenex@hotmail.com says...

>If you really want to slurp in both files then replace your loop with
>the three lines below:
>
>chomp @data1;
>foreach my $index (0..@data1)  {

ITYM
foreach my $index (0..$#data1)  {

>        print OUTPUTFILE "$data1[$index],$data2[$index]";
>}

Cheers

Heinrich

-- 
Heinrich Mislik
Zentraler Informatikdienst der Universitaet Wien
A-1010 Wien, Universitaetsstrasse 7
Tel.: (+43 1) 4277-14056, Fax: (+43 1) 4277-9140



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

Date: Thu, 26 Feb 2009 05:41:08 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: very simple file stitching problem
Message-Id: <bu6dq4596m2ah45dovu0kr9jqj8js2tea7@4ax.com>

Heinrich.Mislik@univie.ac.at (Heinrich Mislik) wrote:
>In article <ehbbq4lnkded19a8le08lp83hc5udtn4aa@4ax.com>, jurgenex@hotmail.com says...

>>foreach my $index (0..@data1)  {
>
>ITYM
>foreach my $index (0..$#data1)  {

Indeed.

But why are you stealth CCing me?

jue


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

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 V11 Issue 2238
***************************************


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