[24018] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6216 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 4 18:06:54 2004

Date: Thu, 4 Mar 2004 15:05:09 -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, 4 Mar 2004     Volume: 10 Number: 6216

Today's topics:
        accessing a hash <hillmw@ram.lmtas.lmco.com>
    Re: accessing a hash <ittyspam@yahoo.com>
    Re: accessing a hash <gnari@simnet.is>
    Re: Anyone got a good one-liner? <bmb@ginger.libs.uga.edu>
    Re: Anyone got a good one-liner? <krahnj@acm.org>
    Re: Can package prefix be avoided? <Joe.Smith@inwap.com>
    Re: Double Jump Box Redirection <mr@sandman.net>
        If elsif beautification <mislam@spamless.uiuc.edu>
    Re: If elsif beautification <ittyspam@yahoo.com>
    Re: If elsif beautification <bmb@ginger.libs.uga.edu>
    Re: If elsif beautification <xx087@freenet.carleton.ca>
    Re: If elsif beautification <mislam@spamless.uiuc.edu>
    Re: If elsif beautification <mislam@spamless.uiuc.edu>
    Re: Need help with Undeliverable Emails <noreply@gunnar.cc>
        Nested arrays <mr@sandman.net>
    Re: new to perl <gnari@simnet.is>
    Re: new to perl <Joe.Smith@inwap.com>
        passing arguments in perl with double quotes (Samantha)
    Re: passing arguments in perl with double quotes <asu1@c-o-r-n-e-l-l.edu>
    Re: passing arguments in perl with double quotes <ittyspam@yahoo.com>
    Re: passing arguments in perl with double quotes <ddunham@redwood.taos.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 04 Mar 2004 14:51:47 -0600
From: Michael Hill <hillmw@ram.lmtas.lmco.com>
Subject: accessing a hash
Message-Id: <404796E3.B6DC5042@ram.lmtas.lmco.com>

I have this hash I'm trying to traverse and having some trouble.

my $var1 = {
          'database' => {
                                 'table' => {
                                              'fields' => {
                                                            'field_name'
=> [
                                                                             
'A',
                                                                             
'B',
                                                                             
'C',
                                                                             
'D'
                                                                           
]
                                                          },
                                              'name' => 'name of table'
                                            }
                               }
        };

This works:

print "$var1->{database}->{table}->{name}\n\n";

print "$var1->{database}->{table}->{fields}->{field_name}->[0]\n";
print "$var1->{database}->{table}->{fields}->{field_name}->[1]\n";
print "$var1->{database}->{table}->{fields}->{field_name}->[2]\n";

Now if I want to loop through all those in:
$var1->{database}->{table}->{fields}->{field_name} ?

I'm attempting to do this pointing directly to an array and loop through
the values but the error message says I am pointing to an element. How
do I point to the elements array?

foreach my $y ( keys %$var1->{database}->{table}->{fields}->{field_name}
) 
	{
	print "$y\n";
	}

Now if I force nested elements to be arrays .... like: 

$var2 = {
          'database' => [
                                 {
                                   'table' => [
                                                {
                                                  'fields' => [
                                                                {
                                                                 
'field_name' => [
                                                                                   
'A',
                                                                                   
'B',
                                                                                   
'C',
                                                                                   
'D'
                                                                                 
]
                                                                }
                                                              ],
                                                  'name' => [
                                                              'name of
table'
                                                            ]
                                                }
                                              ]
                                 }
                               ]
        };

This doesn't work anymore:

print "$var2->{database}->{table}->{name}\n\n";

print "$var2->{database}->{table}->{fields}->{field_name}->[0]\n";

Any how would I loop though the
$var2->{database}->{table}->{fields}->{field_name} elements array?

Thanks,

Mike


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

Date: Thu, 4 Mar 2004 16:18:39 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: accessing a hash
Message-Id: <20040304161608.L27834@dishwasher.cs.rpi.edu>


On Thu, 4 Mar 2004, Michael Hill wrote:

> I have this hash I'm trying to traverse and having some trouble.
>
> my $var1 = {
>           'database' => {
>                                  'table' => {
>                                               'fields' => {
>                                                             'field_name'
> => [
>
> 'A',
>
> 'B',
>
> 'C',
>
> 'D'
>
> ]
>                                                           },
>                                               'name' => 'name of table'
>                                             }
>                                }
>         };
>
> This works:
>
> print "$var1->{database}->{table}->{name}\n\n";
>
> print "$var1->{database}->{table}->{fields}->{field_name}->[0]\n";
> print "$var1->{database}->{table}->{fields}->{field_name}->[1]\n";
> print "$var1->{database}->{table}->{fields}->{field_name}->[2]\n";
>
> Now if I want to loop through all those in:
> $var1->{database}->{table}->{fields}->{field_name} ?
>
> I'm attempting to do this pointing directly to an array and loop through
> the values but the error message says I am pointing to an element. How
> do I point to the elements array?
>
> foreach my $y ( keys %$var1->{database}->{table}->{fields}->{field_name}
> )
> 	{
> 	print "$y\n";
> 	}
>
Your syntax is a bit off.

$var1->{database}->{table}->{fields}->{field_name} is an array reference.
Therefore:
@{$var1->{database}->{table}->{fields}->{field_name} is the array.


So you should have
foreach my $y (@{$var1->{database}->{table}->{fields}->{field_name}) {
	print "$y\n";
}

Paul Lalli


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

Date: Thu, 4 Mar 2004 21:14:48 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: accessing a hash
Message-Id: <c28667$e8f$1@news.simnet.is>

"Michael Hill" <hillmw@ram.lmtas.lmco.com> wrote in message
news:404796E3.B6DC5042@ram.lmtas.lmco.com...
>
> Now if I force nested elements to be arrays .... like:
>
> $var2 = {
>           'database' => [
>                                  {
>                                    'table' => [
>                                                 {
>                                                   'fields' => [
>                                                                 {
>
> 'field_name' => [
>
> 'A',
>
 .....


> This doesn't work anymore:
>
> print "$var2->{database}->{table}->{name}\n\n";
   print "$var2->{database}[0]{table}[0]{fields}[0]{field_name}[0]\n\n";

should print 'A'

gnari





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

Date: Thu, 4 Mar 2004 15:23:59 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Anyone got a good one-liner?
Message-Id: <Pine.A41.4.58.0403041358260.15910@ginger.libs.uga.edu>

On Thu, 4 Mar 2004, Paul Lalli wrote:

> On Thu, 4 Mar 2004, Ben Morrow wrote:
> > No, his point is that this
> >
> > perl -le'$| = 2; print $|'
> >
> > prints 1, not 2. It kinda makes sense, but it isn't documented.
>
> Ohhh.  My mistake.  Apologies to Brad for that one.

Not a problem.  I'm also not sure that I'm recommending the docs be
changed, but the following thoughts occurred to me.

o It makes me think that the value of $| is stored internally as a bit.

o Any use of $| as a boolean flip-flop beyond one-liners and/or
  obfuscation is questionable at best.

o If anyone is using it like this in production code anyway, how likely is
  $|'s behavior in this regard likely to change and break such code?

o This behavior is not what a Perl programmer would expect.  Though Perl
  programmers often expect magic, so maybe I'm wrong.  :-)

o Knowing it's either 1 or 0, one might be inclined to think 'true' and
  'false', but _some_ of Perl's normal ideas of truth and falsehood don't
  apply:

  $| = '0 but true'    # false here, but true elsewhere
  $| = 'alpha string'  # same

o the docs say, "If set to nonzero", and 'hey' is nonzero, but
  $| = 'hey' will not set $| to 1

o if the behavior never changes ++$| is guaranteed to always be 1

I did some cursory unsuccessful searches for earlier discussions about
this but still I might be walking packed earth.  And I suspect this is,
for the most part, a non-problem.  But it is a curiosity.

Regards,

Brad


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

Date: Thu, 04 Mar 2004 21:06:11 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Anyone got a good one-liner?
Message-Id: <40479A35.8C9B76A2@acm.org>

Brad Baxter wrote:
> 
> Not a problem.  I'm also not sure that I'm recommending the docs be
> changed, but the following thoughts occurred to me.
> 
> o It makes me think that the value of $| is stored internally as a bit.

That was my understanding, but I could be wrong.  It certainly acts like
a one bit variable.

> o Any use of $| as a boolean flip-flop beyond one-liners and/or
>   obfuscation is questionable at best.

Definitely.

> o If anyone is using it like this in production code anyway, how likely is
>   $|'s behavior in this regard likely to change and break such code?
> 
> o This behavior is not what a Perl programmer would expect.  Though Perl
>   programmers often expect magic, so maybe I'm wrong.  :-)

No, this is completely expected behavior.  :-)

> o Knowing it's either 1 or 0, one might be inclined to think 'true' and
>   'false', but _some_ of Perl's normal ideas of truth and falsehood don't
>   apply:
> 
>   $| = '0 but true'    # false here, but true elsewhere
>   $| = 'alpha string'  # same

A string in numerical context evaluates to zero unless there is a number
at the beginning of the string.

$ perl -le'
for ( "some string",
      "99some string",
      "99 some string",
      "   99 some string" ) {
    print $_ + 0;  # numerical context
    }
'
0
99
99
99

> o the docs say, "If set to nonzero", and 'hey' is nonzero, but
>   $| = 'hey' will not set $| to 1

'hey' in numerical context IS zero.

> o if the behavior never changes ++$| is guaranteed to always be 1

Yes.


John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 04 Mar 2004 20:19:46 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Can package prefix be avoided?
Message-Id: <BbM1c.179176$uV3.759200@attbi_s51>

Ravisankar Sivasubramaniam wrote:

> Is here a way to do away with the package prefix when employing 'require'?

Yes.  "perldoc -f use".  It says that
   use Test;
is the same as
   BEGIN { require Test; import Test; }
so you need to explictly import the variables and functions from Test.pm.
	-Joe


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

Date: Thu, 04 Mar 2004 22:51:33 +0100
From: Sandman <mr@sandman.net>
Subject: Re: Double Jump Box Redirection
Message-Id: <mr-A715AA.22513304032004@news.fu-berlin.de>

In article <c27bho$e2q$1@wisteria.csv.warwick.ac.uk>,
 Ben Morrow <usenet@morrow.me.uk> wrote:

> > > You're not wrong ... thanks for your help Sandman, nuts to the rest of
> > > you.
> 
> If you're looking for help here, talking like that's hardly going to
> improve your chances...

I don't he will be coming back for more help. :)

> > > I listed the JS just to show what I already had (and wanted to
> > > replace)
> > > Sorry if that wasn't clear.
> > > 
> > > I wanted to use a cgi script and I thought this was an appropriate
> > > place to post.
> > > Sorry if that wasn't clear.
> 
> What wasn't the least bit clear was that you wanted to replace the JS
> with a Perl CGI script.

No?

    "I started using javascript but in my travels have been scared off it.
     So that leave me with pearl."

Despite the spelling mistakes, it was prety clear to me that he wanted to use 
perl instead of JavaScript.

> Also, many of us do not speak JavaScript, so a concise (and complete)
> English description of the problem wouldn't go amiss, either.

Agreed. However, lack of such a description shouldn't warrant the kind of 
replies he recieved.

> Another thing that you seem to unfortunately to have fallen foul of is
> the assumption that perl <=> CGI. This is very much not the case, and
> those of us who know otherwise find it irritating, in the end.

Assuming incorrect things warrants an education, not insults.

> > > Bugger it ... Javascript programmers are friendlier I'll just go and
> > > see them and do it their way. Obviously 5/6 perl programmers are rude.
> 
> Not so much 'are rude' as 'have a different idea of what is rude and
> what is not from most of society'. Here, it is considered rude not to
> explain yourself properly, or not to take the trouble to make sure you've
> spelt the name of the language correctly.

Ergo - not posting according to the posting rules to the last point. Newbies 
make no effort here.

For the record - I don't agree with the above. It was quite clear that *I* 
could understand his problem and even help him out - and even without giving 
him attitude..

> > Not really, but many oldies in this group are eager to complain about what
> > they feel are posts that aren't up to a certain standard. They have no
> > tolerance for newbies. 
> 
> s/newbies/clueless newbies/. I joined this group as a newbie a while
> ago, and have never found it unfriendly. I was smacked a couple of times
> for making stupid mistakes, but that's what you should expect for
> stupidity.

No, that's just plain wrong. Being ignorant doesn't mean people have a free 
pass at making fun at you. Especially not in a *.misc group.

> > It's a shame, since it's a *.misc group. there are posting "rules"
> > here, and they are a great reference, but being naive enough to think
> > that everyone should follow them is a little too much.
> 
> It's not a question of naivete. It's a question of 'if you're not even
> going to bother to read and follow a few simple guidelines, why should I
> bother to spend time trying to help you?'.

What I meant was that it is naive to believe that a newbie would actually look 
through the group to see if there is a posting rules document (which may or may 
not have been posted in time for his feed to have picked it up). Having posting 
rules isn't very common on usenet, you know.

I am all FOR posting styles. And when you get your first reference to them (as 
he should have gotten, instead of attitude) you can read them and adhere to 
them as good as you can.

> > You posted to the correct group and I hope my post at least helped some.
> 
> You are indeed (probably) in the right place, and I would have thought
> that if you try again with a little more respect for the conventions of
> this group that you will find it not unhelpful.

It is true that the chance of getting help is in direct relation to your 
awareness of these documents - but "respect" isn't the right word. It was lack 
of respect that brought us here, but not from him.

Some words of wisdoms for our resident oldies:

1. Don't ever EXPECT everyone to have thoroughly read through the FAQ and 
posting styles documents for this group before they post their first post.

2. Treat people with respect, and direct them to the above documents when they 
are posting things that will make it hard for them to recieve proper help in 
this group.

3. Hit the 'cancel' button if you realise that the reply you begun typing is 
laced with sarcasm and just plain bad attitude.

4. This isn't a contest. You can't win anything here.

-- 
Sandman[.net]


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

Date: Thu, 04 Mar 2004 14:43:50 -0600
From: Sharif Islam <mislam@spamless.uiuc.edu>
Subject: If elsif beautification
Message-Id: <c284e6$pfj$1@news.ks.uiuc.edu>

Based on some matched patterns I am setting the var $id and applying two 
functions -- code snippet below. The code looks really ugly when I have 
25 elsif statements for the match. The parts that are different on each 
line are the url pattern and the id. I am applying the same two 
functions in each line. Is there any way to combine the if/elsif 
statements and the function calls? Thanks.


foreach $line (@url) {

if ($line =~ /google.com/) { print "----\n$line\n" ;  $id =55 ; 
myFunction($dbh,$line,$id); myAnotherFunction($dbh,$id); }
elsif ($line =~ /slashdot.org/) { print "---\n$line\n" ; $id = 64; 
myFunction($dbh,$line,$id); myAnotherFunction($dbh;$id); }
elsif ($line =~ /yahoo.com/) { print "---\n$line\n" ; $id = 12; 
myFunction($dbh,$line,$id); myAnotherFunction($dbh;$id); }

#20 or so pattern match

   }


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

Date: Thu, 4 Mar 2004 15:54:36 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: If elsif beautification
Message-Id: <20040304154851.F27834@dishwasher.cs.rpi.edu>

On Thu, 4 Mar 2004, Sharif Islam wrote:

> Based on some matched patterns I am setting the var $id and applying two
> functions -- code snippet below. The code looks really ugly when I have
> 25 elsif statements for the match. The parts that are different on each
> line are the url pattern and the id. I am applying the same two
> functions in each line. Is there any way to combine the if/elsif
> statements and the function calls? Thanks.
>
>
> foreach $line (@url) {
>
> if ($line =~ /google.com/) { print "----\n$line\n" ;  $id =55 ;
> myFunction($dbh,$line,$id); myAnotherFunction($dbh,$id); }
> elsif ($line =~ /slashdot.org/) { print "---\n$line\n" ; $id = 64;
> myFunction($dbh,$line,$id); myAnotherFunction($dbh;$id); }
> elsif ($line =~ /yahoo.com/) { print "---\n$line\n" ; $id = 12;
> myFunction($dbh,$line,$id); myAnotherFunction($dbh;$id); }
>
> #20 or so pattern match
>
>    }
>

I would establish a hash before this mess, have a nested loop, and remove
the stuff from the if statement that's being done no matter what:

%url_ids = (
	'google.com' => 55,
	'slashdot.org' => 64,
	'yahoo.com' => 12,
	<etc>);

foreach $line (@url){
	print "----\n$line\n";
	foreach $url (keys %url_ids){
		$id = $url_ids{$url} if $line =~ /$url/;
	}
	myFunction($dbh, $line, $id);
	myAnotherFunction($dbh, $id);
}


Note that if you actually have lines populating @url that are equal to the
urls, rather than simply contain the urls, you don't even need the inner
loop.  You can simply say $id = $url_ids{$url};

Paul Lalli


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

Date: Thu, 4 Mar 2004 16:46:33 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: If elsif beautification
Message-Id: <Pine.A41.4.58.0403041617010.15910@ginger.libs.uga.edu>

On Thu, 4 Mar 2004, Sharif Islam wrote:

> Based on some matched patterns I am setting the var $id and applying two
> functions -- code snippet below. The code looks really ugly when I have
> 25 elsif statements for the match. The parts that are different on each
> line are the url pattern and the id. I am applying the same two
> functions in each line. Is there any way to combine the if/elsif
> statements and the function calls? Thanks.
>
>
> foreach $line (@url) {
>
> if ($line =~ /google.com/) { print "----\n$line\n" ;  $id =55 ;
> myFunction($dbh,$line,$id); myAnotherFunction($dbh,$id); }
> elsif ($line =~ /slashdot.org/) { print "---\n$line\n" ; $id = 64;
> myFunction($dbh,$line,$id); myAnotherFunction($dbh;$id); }
> elsif ($line =~ /yahoo.com/) { print "---\n$line\n" ; $id = 12;
> myFunction($dbh,$line,$id); myAnotherFunction($dbh;$id); }
>
> #20 or so pattern match
>
>    }
>

Here's how I might attempt this:

# add your 20 or so other patterns here
my %codes = qw(
    google.com   55
    slashdot.org 64
    yahoo.com    12
);

my $url_re = qr/@{['('.join( '|', map "\Q$_\E", keys %codes ).')']}/;

foreach my $line ( @url ) {
    if( $line =~ $url_re ) {
        my $id = $codes{ $1 };
        print "----\n$line matched '$1'\n";
        myFunction( $dbh, $line, $id );
        myAnotherFunction( $dbh, $id );
    }
}

And I suppose that $line isn't going to contain something like

    http://www.vitabrevis.com/cgi-bin/boo.cgi?url=www.google.com

and possibly give you misleading results?  :-)

If it might, then your patterns may need rethinking ...

Regards,

Brad


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

Date: 4 Mar 2004 22:06:13 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: If elsif beautification
Message-Id: <slrnc4fa2l.j4e.xx087@smeagol.ncf.ca>

Sharif Islam <mislam@spamless.uiuc.edu> wrote:
>  Based on some matched patterns I am setting the var $id and applying two 
>  functions -- code snippet below. The code looks really ugly when I have 
>  25 elsif statements for the match. The parts that are different on each 
>  line are the url pattern and the id. I am applying the same two 
>  functions in each line. Is there any way to combine the if/elsif 
>  statements and the function calls? Thanks.
>  
>  
>  foreach $line (@url) {
>  
>  if ($line =~ /google.com/) { print "----\n$line\n" ;  $id =55 ; 
>  myFunction($dbh,$line,$id); myAnotherFunction($dbh,$id); }
>  elsif ($line =~ /slashdot.org/) { print "---\n$line\n" ; $id = 64; 
>  myFunction($dbh,$line,$id); myAnotherFunction($dbh;$id); }
>  elsif ($line =~ /yahoo.com/) { print "---\n$line\n" ; $id = 12; 
>  myFunction($dbh,$line,$id); myAnotherFunction($dbh;$id); }
>  
>  #20 or so pattern match
>  
>     }


Whitespace won't kill you.

    foreach $line (@url) {
        my $id;  # an undefined value

        if    ($line =~ /google.com/)   { $id = 55; }
        elsif ($line =~ /slashdot.org/) { $id = 64; }
        elsif ($line =~ /yahoo.com/)    { $id = 12; }
        #...

        next unless $id;
        
        # now that an id is set, do something with it:
        print "----\n$line\n";
        myFunction($dbh,$line,$id); 
        myAnotherFunction($dbh,$id);
    }
            



-- 
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca


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

Date: Thu, 04 Mar 2004 16:49:51 -0600
From: Sharif Islam <mislam@spamless.uiuc.edu>
Subject: Re: If elsif beautification
Message-Id: <c28bqf$s3h$1@news.ks.uiuc.edu>

Paul Lalli wrote:

> On Thu, 4 Mar 2004, Sharif Islam wrote:
> 
> 
>>Based on some matched patterns I am setting the var $id and applying two
>>functions -- code snippet below. The code looks really ugly when I have
>>25 elsif statements for the match. The parts that are different on each
>>line are the url pattern and the id. I am applying the same two
>>functions in each line. Is there any way to combine the if/elsif
>>statements and the function calls? Thanks.
>>
>>
>>foreach $line (@url) {
>>
>>if ($line =~ /google.com/) { print "----\n$line\n" ;  $id =55 ;
>>myFunction($dbh,$line,$id); myAnotherFunction($dbh,$id); }
>>elsif ($line =~ /slashdot.org/) { print "---\n$line\n" ; $id = 64;
>>myFunction($dbh,$line,$id); myAnotherFunction($dbh;$id); }
>>elsif ($line =~ /yahoo.com/) { print "---\n$line\n" ; $id = 12;
>>myFunction($dbh,$line,$id); myAnotherFunction($dbh;$id); }
>>
>>#20 or so pattern match
>>
>>   }
>>
> 
> 
> I would establish a hash before this mess, have a nested loop, and remove
> the stuff from the if statement that's being done no matter what:
> 
> %url_ids = (
> 	'google.com' => 55,
> 	'slashdot.org' => 64,
> 	'yahoo.com' => 12,
> 	<etc>);
> 
> foreach $line (@url){
> 	print "----\n$line\n";
> 	foreach $url (keys %url_ids){
> 		$id = $url_ids{$url} if $line =~ /$url/;
> 	}
> 	myFunction($dbh, $line, $id);
> 	myAnotherFunction($dbh, $id);
> }
> 
> 
> Note that if you actually have lines populating @url that are equal to the
> urls, rather than simply contain the urls, you don't even need the inner
> loop.  You can simply say $id = $url_ids{$url};
> 

Thanks. That was helpful. The code looks much better now.


-- 
     )
    ((
   |""|-.
   | :|/'
  -`--'-


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

Date: Thu, 04 Mar 2004 16:51:23 -0600
From: Sharif Islam <mislam@spamless.uiuc.edu>
Subject: Re: If elsif beautification
Message-Id: <c28btb$s3h$2@news.ks.uiuc.edu>

Brad Baxter wrote:

> On Thu, 4 Mar 2004, Sharif Islam wrote:

[....]


> Here's how I might attempt this:
> 
> # add your 20 or so other patterns here
> my %codes = qw(
>     google.com   55
>     slashdot.org 64
>     yahoo.com    12
> );
> 
> my $url_re = qr/@{['('.join( '|', map "\Q$_\E", keys %codes ).')']}/;
> 
> foreach my $line ( @url ) {
>     if( $line =~ $url_re ) {
>         my $id = $codes{ $1 };
>         print "----\n$line matched '$1'\n";
>         myFunction( $dbh, $line, $id );
>         myAnotherFunction( $dbh, $id );
>     }
> }
> 
> And I suppose that $line isn't going to contain something like
> 
>     http://www.vitabrevis.com/cgi-bin/boo.cgi?url=www.google.com
> 
> and possibly give you misleading results?  :-)
> 
> If it might, then your patterns may need rethinking ...

Thanks. My @url only contains the hostname extract from the actual urls. 
So it should be ok.



-- 
     )
    ((
   |""|-.
   | :|/'
  -`--'-


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

Date: Thu, 04 Mar 2004 21:27:54 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Need help with Undeliverable Emails
Message-Id: <c283hd$1qpdp1$1@ID-184292.news.uni-berlin.de>

great places to stay. wrote:
> My problem is when my perl script sends out an email using perls
> /sendmail

Perl's sendmail? It sounds to me as if you are using a sendmail mail
transfer agent provided by your hosting provider. Even if the program
you are using is written in Perl, and you open a pipe to the sendmail
MTA from it, sendmail is not a Perl feature.

> to one of my users, that have added their email address to one of
> my forms the email is bounced back if it is undeliverable.
> 
> The problem I have is my ISP can't work out how to get those
> bounced emails to be sent back to my email address so I am aware
> that an email sent by /sendmail in perl has not been delivered.

I have experienced the same problem, and the solution in my case is to
use a Perl module that does not make use of sendmail. The CPAN module
Mail::Sender lets you conveniently control the return-path from your
Perl program. (I don't know about other mail sending modules.)

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Thu, 04 Mar 2004 23:19:38 +0100
From: Sandman <mr@sandman.net>
Subject: Nested arrays
Message-Id: <mr-12CDF3.23193804032004@news.fu-berlin.de>

Using php, an array definition might look like this:

    $foo = array(
        "foo" => array("foo", "bar"),
        "bar" => array("rab", "oof")
    );

    print $foo["foo"][0];

 ...would print "foo"

    $foo = array(
        "foo" => array("foo" => "orange", "bar" => "apple"),
        "bar" => array("rab" => "pear", "oof" => "pineapple")
    );

    print $foo["foo"][0];
    print $foo["foo"]["foo"];

 ...would both print "orange".

How would the syntax be in perl? Perl differantiates betwen hashes and arrays, 
and in php an array is an hash and an array at the same time (i.e. every key in 
the array exists as both named and as index).

-- 
Sandman[.net]


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

Date: Thu, 4 Mar 2004 19:59:51 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: new to perl
Message-Id: <c281pm$deu$1@news.simnet.is>

"Tony Muler" <t_lawetta@yahoo.com> wrote in message
news:40472dba$1_1@news.vo.lu...
> Regent wrote:
>
> > Tsui Wai-ming wrote:
> >
> >> I just started to learn CGI by writing a perl script, but what
> >> appeared on
> >> the browser was exactly what I'd typed in the editor, minus the
> >> <title>xxx</title> line.
> [...]
>
> > Why not tell us WHAT is on the browser.
>
> He said it: Exactly what was typed into the editor.
> This means that the file is treated as a normal
> text file by the webserver, not as a CGI script.
> It was not executed but just displayed.

what's the bit with the 'minus the <title>xxx</title> line' then ?

gnari







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

Date: Thu, 04 Mar 2004 20:34:24 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: new to perl
Message-Id: <jpM1c.177224$jk2.647006@attbi_s53>

Tsui Wai-ming wrote:

> In fact I just changed to
> 
> #!C:\perl\bin\perl
> 
> This one
> # perl, and
> #!C:\perl\bin
> 
> didnt work at all...

It depends on how you invoke your perl script.

Double-clicking on an icon in a local file folder: Uses registry.
Typing name into CMD.EXE command-line prompt: Uses registry.
Typing name into some other command-line shell: Depends on shell (bash).
    (In particular, cygwin uses /usr/bin/perl.)
Clicking on link in a browser: Depends on web server.
    Sambar Server for Windows: Uses shebang line.
    Apache Server for Windows: I believe it is a configuration option.
    IIS: Registry.

Which method "didnt work at all"?
	-Joe


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

Date: 4 Mar 2004 13:05:05 -0800
From: samwillquit@yahoo.com (Samantha)
Subject: passing arguments in perl with double quotes
Message-Id: <9e9be093.0403041305.311a15aa@posting.google.com>

Hi,

I would like to know how I can pass double quotes to a perl script. ie
I have a test script which has:
#!/usr/local/bin/perl5
print "arg0\n";
print @ARGV[0];
print "\narg1\n";
print @ARGV[1];
print "\narg2\n";
print @ARGV[2];
print "\n";

and I say:
 ./test  hello  "1 2"
arg0
hello
arg1
1 2
arg2

I would like arg1 to be "1 2" and not just 1 2
It looks like the " are being stripped out of the argument by the
parser. Similarly, I would like:
 ./test  hello  '1 2'
arg0
hello
arg1
1 2
arg2

to print '1 2' for arg1. 

the reson I need this is because I am passing "1 2" to another script
which requires these arguments to have "" around them. If the " is
missing, it only reads 1 instead of 1 2

Thanks in advance for any help,

Sam


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

Date: 4 Mar 2004 21:19:21 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: passing arguments in perl with double quotes
Message-Id: <Xns94A2A60ADD622asu1cornelledu@132.236.56.8>

samwillquit@yahoo.com (Samantha) wrote in 
news:9e9be093.0403041305.311a15aa@posting.google.com:

> Hi,
> 
> I would like to know how I can pass double quotes to a perl script. ie
> I have a test script which has:

Depends on your shell. Using cmd.exe on Win2K:

C:\Home> cat t.pl

#! C:\opt\Perl\bin\perl.exe

use strict;
use warnings;

for my $i (0 .. $#ARGV) {
	print "\$ARGV[$i] = ", $ARGV[$i], "\n";
}

C:\Home> perl t.pl "\"1 2 3 4 5\""
$ARGV[0] = "1 2 3 4 5"

C:\Home> perl t.pl "'1 2 3 4 5'"
$ARGV[0] = '1 2 3 4 5'

So, look it up in your shell's documentation.

Sinan.


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

Date: Thu, 4 Mar 2004 16:22:42 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: passing arguments in perl with double quotes
Message-Id: <20040304162045.B27834@dishwasher.cs.rpi.edu>

On Thu, 4 Mar 2004, Samantha wrote:

> Hi,
>
> I would like to know how I can pass double quotes to a perl script. ie
> I have a test script which has:
> #!/usr/local/bin/perl5
> print "arg0\n";
> print @ARGV[0];
> print "\narg1\n";
> print @ARGV[1];
> print "\narg2\n";
> print @ARGV[2];
> print "\n";
>
> and I say:
> ./test  hello  "1 2"
> arg0
> hello
> arg1
> 1 2
> arg2
>
> I would like arg1 to be "1 2" and not just 1 2
> It looks like the " are being stripped out of the argument by the
> parser. Similarly, I would like:

This isn't perl's doing, it's the shell.  Quotes are a special character
that mean "all of the following until the next quote are one argument,
regardless of space".  If you want to include actual quote characters in
your argument, you do:
 ./test hello \"1\ 2\"

The second slash is now necessary because the " are no longer special, and
so the space would normally be treated as an argument separation
character.

Paul Lalli


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

Date: Thu, 04 Mar 2004 22:49:28 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: passing arguments in perl with double quotes
Message-Id: <YnO1c.19993$x06.10149@newssvr29.news.prodigy.com>

Paul Lalli <ittyspam@yahoo.com> wrote:
>> I would like arg1 to be "1 2" and not just 1 2
>> It looks like the " are being stripped out of the argument by the
>> parser. Similarly, I would like:

> This isn't perl's doing, it's the shell.  Quotes are a special character
> that mean "all of the following until the next quote are one argument,
> regardless of space".  If you want to include actual quote characters in
> your argument, you do:
> ./test hello \"1\ 2\"

> The second slash is now necessary because the " are no longer special, and
> so the space would normally be treated as an argument separation
> character.

Or just use single quotes around them (on a unix style shell)

$ perl -le 'print foreach @ARGV' hi there
hi
there
$ perl -le 'print foreach @ARGV' "hi there"
hi there
$ perl -le 'print foreach @ARGV' '"hi there"'
"hi there"

-- 
Darren Dunham                                           ddunham@taos.com
Senior Technical Consultant         TAOS            http://www.taos.com/
Got some Dr Pepper?                           San Francisco, CA bay area
         < This line left intentionally blank to confuse you. >


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

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 6216
***************************************


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