[23142] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5363 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 14 21:05:39 2003

Date: Thu, 14 Aug 2003 18:05:06 -0700 (PDT)
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, 14 Aug 2003     Volume: 10 Number: 5363

Today's topics:
    Re: Extremely Basic mySQL question. <noreply@gunnar.cc>
        hand crafting soap for google api's <scripts_you-know-the-drill_@hudsonscripting.com>
    Re: hand crafting soap for google api's <scripts_you-know-the-drill_@hudsonscripting.com>
    Re: Help w/ BNB Survey Script <-- <chessql@highstream.net>
    Re: Help w/ BNB Survey Script <-- <kkeller-spammmm@wombat.san-francisco.ca.us>
    Re: Installation of Perl/Tk on WindowsXP <r_reidy@comcast.net>
    Re: Newbie question !! (James Willmore)
    Re: Perl and recursive copying? (James Willmore)
    Re: Problem with join and unicode <flavell@mail.cern.ch>
    Re: Question about "eval" security <hisao@physics.purdue.edu>
    Re: Question about "eval" security <chesucat@freeshell.org>
    Re: question about sigtrap! (James Willmore)
        question regarding multiple args to sub  <abc@nowhere.com>
    Re: sort multi-key hash by value and print out with key (Antonio Quinonez)
    Re: strange error  "Unsuccessful stat on filename " (James Willmore)
    Re: Suggestions for further perl reading <spamblock@junkmail.com>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 15 Aug 2003 00:56:51 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Extremely Basic mySQL question.
Message-Id: <bhh439$f7gf$1@ID-184292.news.uni-berlin.de>

Tyler Cruz wrote:
> I was wondering how should I download the mySQL dump to my computer
> via FTP? ASCII or binary? Or does it matter?

Basically, since a MySQL dump is a text file, the latter is true. But, 
assuming you do it for backup reasons, and to be on the safe side that
nothing is changed during the transfer, I'd use binary.

Please don't further prolong this thread in two news groups with this
totally off topic subject.

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



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

Date: Thu, 14 Aug 2003 19:47:38 -0700
From: Hudson <scripts_you-know-the-drill_@hudsonscripting.com>
Subject: hand crafting soap for google api's
Message-Id: <ushojv0hhdddalnbf2550i53ja1eqo192d@4ax.com>

#!/usr/bin/perl -w
use strict;
Hi all, today I went looking to do something with the google api's.
But...all the examples I found used soap::light and that is not
in my @INC on my server.

So I banged out this example...doesn't seem so hard. Is this all there 
is too it, any advice/critiques, etc or feed back?

must name nph-somefile.cgi -> nonparsed headers

#!/usr/bin/perl -w
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use IO::Socket;

my $sleep_time = 1;

my $query = new CGI;
    print "HTTP/1.0 200 OK\n"; 
    print "Content-Type: text/html\r\n\r\n";
    print "<html><head><body>";
    print "<hr noshade width=\"65%\">";   
    print "<center><h2>Google's 10 ten URL's via web services (SOAP)<\/h2>";
    print "Enter one keyword or phrase per line (limit of 1,000 searches a day)";    
&print_prompt($query);
&do_work($query);

print $query->end_html;
 
# --------------------------------------------------------- subroutines: cgi.pm

sub print_prompt {
 
    my($query) = @_;
    print $query->startform;
    print $query->textarea(-name=>'domains',
                           -rows=>8,
                           -columns=>30);
    print "<br><br>";
    print $query->submit(-name=>'find those dirty dogs');
    print $query->endform;
}


sub do_work {
    unless ($query->param) {
        return;
        }
    my $query_string = $query->param('domains');
    my @domains = split(/\n/, $query_string);

    metatags (@domains);
    print "</body></html>";    

}


# -------------------------------------------------------- subroutine: get data

sub metatags {
    $|=1;

    my @keywords = @_;
    foreach my $keyword (@keywords) {
        $keyword =~ s/\s+$//;
                
        my $soap_request .= "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\">\n";
        $soap_request .= "<SOAP-ENV:Body>\n";
        $soap_request .= "<ns1:doGoogleSearch xmlns:ns1=\"urn:GoogleSearch\" \n";
        $soap_request .= "SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n";
        $soap_request .= "<key xsi:type=\"xsd:string\">***_your_key_here_***</key>\n";
        $soap_request .= "<q xsi:type=\"xsd:string\">$keyword</q>\n";
        $soap_request .= "<start xsi:type=\"xsd:int\">0</start>\n";
        $soap_request .= "<maxResults xsi:type=\"xsd:int\">10</maxResults>\n";
        $soap_request .= "<filter xsi:type=\"xsd:boolean\">true</filter>\n";
        $soap_request .= "<restrict xsi:type=\"xsd:string\"></restrict>\n";
        $soap_request .= "<safeSearch xsi:type=\"xsd:boolean\">false</safeSearch>\n";
        $soap_request .= "<lr xsi:type=\"xsd:string\"></lr>\n";
        $soap_request .= "<ie xsi:type=\"xsd:string\">latin1</ie>\n";
        $soap_request .= "<oe xsi:type=\"xsd:string\">latin1</oe>\n";
        $soap_request .= "</ns1:doGoogleSearch>\n";
        $soap_request .= "</SOAP-ENV:Body>\n";
        $soap_request .= "</SOAP-ENV:Envelope>";
    
        my $request = "POST /search/beta2 HTTP/1.1\n";
        $request .= "Host: api.google.com\n";
        $request .= "Accept-Encoding: identity\n";
        $request .= "Content-length: ".length($soap_request)."\n";
        $request .= "SOAPAction: \"urn:GoogleSearchAction\"\n";
        $request .= "Content-Type: text/xml\; charset=utf-8\n\n";
        $request .= "$soap_request";        

        my $socket = IO::Socket::INET->new(PeerAddr => "api.google.com",
                                           PeerPort => 80,
                                           Proto    => "tcp",
                                           Type     => SOCK_STREAM,
                                           Timeout  => 5);
        print $socket $request;
    
        print "<b>$keyword:</b><br>";

        while (<$socket>) { 

        if ($_ =~ /<URL xsi:type=\"xsd:string\">(.*)<\/URL>/) {   
            print "<a href=\"$1\">$1</a><br>";
        }       
    }
    print "<hr>";
    close($socket);
    sleep $sleep_time;
    }
}



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

Date: Thu, 14 Aug 2003 20:26:31 -0700
From: Hudson <scripts_you-know-the-drill_@hudsonscripting.com>
Subject: Re: hand crafting soap for google api's
Message-Id: <hlkojv0qpj2cob78h82iuvffsntnagalpl@4ax.com>

whoops...kind of messed up on that post...here is the code:

must name nph-somefile.cgi -> nonparsed headers

#!/usr/bin/perl -w
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use IO::Socket;

my $sleep_time = 1;

my $query = new CGI;
    print "HTTP/1.0 200 OK\n"; 
    print "Content-Type: text/html\r\n\r\n";
    print "<html><head><body>";
    print "<hr noshade width=\"65%\">";   
    print "<center><h2>Google's 10 ten URL's via web services (SOAP)<\/h2>";
    print "Enter one keyword or phrase per line (limit of 1,000 searches a day)";    
&print_prompt($query);
&do_work($query);

print $query->end_html;
 
# --------------------------------------------------------- subroutines: cgi.pm

sub print_prompt {
 
    my($query) = @_;
    print $query->startform;
    print $query->textarea(-name=>'domains',
                           -rows=>8,
                           -columns=>30);
    print "<br><br>";
    print $query->submit(-name=>'find those dirty dogs');
    print $query->endform;
}


sub do_work {
    unless ($query->param) {
        return;
        }
    my $query_string = $query->param('domains');
    my @domains = split(/\n/, $query_string);

    metatags (@domains);
    print "</body></html>";    

}


# -------------------------------------------------------- subroutine: get data

sub metatags {
    $|=1;

    my @keywords = @_;
    foreach my $keyword (@keywords) {
        $keyword =~ s/\s+$//;
                
        my $soap_request .= "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\">\n";
        $soap_request .= "<SOAP-ENV:Body>\n";
        $soap_request .= "<ns1:doGoogleSearch xmlns:ns1=\"urn:GoogleSearch\" \n";
        $soap_request .= "SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n";
        $soap_request .= "<key xsi:type=\"xsd:string\">***_your_key_here_***</key>\n";
        $soap_request .= "<q xsi:type=\"xsd:string\">$keyword</q>\n";
        $soap_request .= "<start xsi:type=\"xsd:int\">0</start>\n";
        $soap_request .= "<maxResults xsi:type=\"xsd:int\">10</maxResults>\n";
        $soap_request .= "<filter xsi:type=\"xsd:boolean\">true</filter>\n";
        $soap_request .= "<restrict xsi:type=\"xsd:string\"></restrict>\n";
        $soap_request .= "<safeSearch xsi:type=\"xsd:boolean\">false</safeSearch>\n";
        $soap_request .= "<lr xsi:type=\"xsd:string\"></lr>\n";
        $soap_request .= "<ie xsi:type=\"xsd:string\">latin1</ie>\n";
        $soap_request .= "<oe xsi:type=\"xsd:string\">latin1</oe>\n";
        $soap_request .= "</ns1:doGoogleSearch>\n";
        $soap_request .= "</SOAP-ENV:Body>\n";
        $soap_request .= "</SOAP-ENV:Envelope>";
    
        my $request = "POST /search/beta2 HTTP/1.1\n";
        $request .= "Host: api.google.com\n";
        $request .= "Accept-Encoding: identity\n";
        $request .= "Content-length: ".length($soap_request)."\n";
        $request .= "SOAPAction: \"urn:GoogleSearchAction\"\n";
        $request .= "Content-Type: text/xml\; charset=utf-8\n\n";
        $request .= "$soap_request";        

        my $socket = IO::Socket::INET->new(PeerAddr => "api.google.com",
                                           PeerPort => 80,
                                           Proto    => "tcp",
                                           Type     => SOCK_STREAM,
                                           Timeout  => 5);
        print $socket $request;
    
        print "<b>$keyword:</b><br>";

        while (<$socket>) { 

        if ($_ =~ /<URL xsi:type=\"xsd:string\">(.*)<\/URL>/) {   
            print "<a href=\"$1\">$1</a><br>";
        }       
    }
    print "<hr>";
    close($socket);
    sleep $sleep_time;
    }
}



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

Date: Thu, 14 Aug 2003 16:42:55 -0600
From: Lori Fleetwood <chessql@highstream.net>
Subject: Re: Help w/ BNB Survey Script <--
Message-Id: <26U_a.2929$Q5.1313@fe01.atl2.webusenet.com>

Keith Keller wrote:
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
> 
> In article <3NS_a.2848$Q5.1404@fe01.atl2.webusenet.com>, Lori Fleetwood wrote:
> 
>>I don't know how you've become so good with Perl with one half of your 
>>brain apparently turned off: just because perl and usenet are not the 
>>same does not mean that how people approach the two of them cannot be 
>>compared.  You'd probably be a Perl god if you didn't think in such a 
>>linear fashion all the time.  Perhaps you know this and the frustration 
>>is why you can be such a d!ckhead at times.
> 
> 
> Perhaps you could spend your time answering the OP, since you seem so
> offended at efforts not to do so?

Perhaps you could spend your time answering the OP, since you seem so 
offended by someone offended at efforts not to do so?

Go ahead....I dare you to reply ;)




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

Date: Thu, 14 Aug 2003 17:30:19 -0700
From: Keith Keller <kkeller-spammmm@wombat.san-francisco.ca.us>
Subject: Re: Help w/ BNB Survey Script <--
Message-Id: <ri9hhb.4u1.ln@goaway.wombat.san-francisco.ca.us>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

In article <26U_a.2929$Q5.1313@fe01.atl2.webusenet.com>, Lori Fleetwood wrote:
> Keith Keller wrote:
>> 
>> Perhaps you could spend your time answering the OP, since you seem so
>> offended at efforts not to do so?
> 
> Perhaps you could spend your time answering the OP, since you seem so 
> offended by someone offended at efforts not to do so?

Perhaps you could spend your time answering the OP, since you seem so 
offended by me offended by you offended by efforts not to do so?

Next time I write a perl script for this.  :)

sub offended {

my $self=shift;
if ($self->{'offended'})
{
	$self->ask('answer OP');
	++$self->{'offended'};
	$self->offended;
}

$self->{'offended'}=0;

} # end sub offended


# killall -TERM thread

- --keith

- -- 
kkeller-mmmspam@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj88KZcACgkQhVcNCxZ5ID8K2QCfWHQV9dQh9UpqEXQeiHN62THl
jX0AnAjwf6/AKWJnqYHOoqNyLhTVsVkk
=HnXv
-----END PGP SIGNATURE-----


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

Date: Thu, 14 Aug 2003 18:08:44 -0600
From: Ron Reidy <r_reidy@comcast.net>
Subject: Re: Installation of Perl/Tk on WindowsXP
Message-Id: <3F3C248C.5030306@comcast.net>

See below ...

Hans wrote:
> Is anyone knowing how I can get and install the Perl/Tk Suite/Modul on 
> WindowsXP without compiling. I can't find it under Activestate. I have 
> installed Perl 5.6.1 Activestate on my Computer. I yet only found Tk as 
> source files not as binaries, and I have no VisualC++ Compiler or make 
> -- and nmake 1.5 doesn't work without problems.
Did you try using 'ppm'?

> 
> Now for short: Does anybody know a URL where I can download Tk binairies 
> for WindowsXP/NT?
http://ppm.activestate.com/PPMPackages/zips/6xx-builds-only/

> 
> Thanks a lot!
> 


-- 
Ron Reidy
Oracle DBA



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

Date: 14 Aug 2003 16:43:40 -0700
From: jwillmore@cyberia.com (James Willmore)
Subject: Re: Newbie question !!
Message-Id: <e0160815.0308141543.5a876873@posting.google.com>

> Hi !
> 
> What is the different between ??
> 
> #!/usr/bin/perl -w
> and 
> #!/usr/bin/perl
> 
> 
> I'm newbie, I just start to learn perl
> 
> Thanks

The difference is, in a nutshell,  
one will issue warnings (-w), the other will not.

Since you are a newbie, try reading the documentation that came with Perl.

type:
perldoc perl

at the command line and start reading.

HTH

Jim


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

Date: 14 Aug 2003 17:12:53 -0700
From: jwillmore@cyberia.com (James Willmore)
Subject: Re: Perl and recursive copying?
Message-Id: <e0160815.0308141612.7bcd8576@posting.google.com>

> I'm trying to write a web based perl script that writes a self 
> replicating website.
> For now, I'm trying to have it copy the contents of
> /usr/apache/joe
> to /usr/apache/bill.
> 
> So I need it to programmatically create bill and copy the entire 
> contents of joe...I'm using Perl 5.6.0 and none of the File::Copy 
> commands are working, or I am doing it wrong..anyone have a bone to 
> throw? thanks

UNTESTED
========
#!/usr/bin/perl -w

use strict;
use vars qw/$joe $bill/;

$joe = '/usr/apache/joe';
$bill = '/usr/apache/bill';

open(JOE, "< $joe") or 
    die "Can't open $joe: $!\n";
open(BILL, "> $bill") or
    die "Can't open $bill: $!\n";

while(<JOE>){
    print BILL $_;
}

close JOE;
close BILL;

exit;
===============

This should work for text (aka HTML) files.  
There are other methods that will lend better granularity, 
error checking, etc., but this is probably the 'cheapest' way to do it.

If you post the code using File::Copy, 
maybe we can see what you may have done and offer suggestions.

HTH

Jim


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

Date: Fri, 15 Aug 2003 00:04:47 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Problem with join and unicode
Message-Id: <Pine.LNX.4.53.0308142324070.8715@lxplus103.cern.ch>

On Wed, Aug 13, derek / nul inscribed on the eternal scroll:

> Please keep in mind I am at best a part time programmer,

That's why it's important to do the job the right way, rather than
trying to re-implement assembler-level code (which is what working
utf-16 in bytes pretty-much amounts to) in Perl.

> who is nor conversant
> with C.  I say this because Perl people seem to quote C examples a lot.

But in this case you've got the wrong end of the stick.  We're aiming
to use Perl's native Unicode support.  I'm not aware of anything
comparable in C.

> My ugly code is at the bottom,

Well, OK, but I'm going to have to point you at the group posting
guidelines, masterfully collated by Tad, about the best way to make
use of the resources of this group.  You need (for your own good as
well as being the best way to ask a question) a *minimal* script which
demonstrates the substantive point at issue.

So in this case I'd suggest it would need to read one substantive
external file (which, on the evidence, appears to be in utf-16LE),
make some mickey-mouse change to it, and then write it out again in
the required format.  Once you had that working as intended, it would
be time to build upon that to solve your real problem.

> Ok, I have read through the 2 links below, but all I seem to get is
> that utf8 is the default with 5.8.

5.8 will go into utf8 mode if it's forced to, or if it's told to.
It'll stay back in 8-bit coded mode if it can get away with it.  But
as the docu tries to explain: if you're working conscientiously in
character mode, that should take care of itself as far as Perl
internals are concerned.  Just don't try to fiddle around with the
actual byte patterns: stick to the characters.  Is my advice, anyway.

> I am at a loss as to how to implement what you are saying, any
> pointers to some code perhaps.

I'd like to help, but at the moment I'm afraid we're bogged down in
the current MS-Windows security panic.  We've tried to get rid of MS
many a time for security reasons, but the users won't let us - but of
course when it all goes pear-shaped they expect their hands to be held
for them.  It's all very frustrating.  (This is back at the campus,
nothing to do with CERN - I have to say that in case of
misunderstandings).

> >There was a discussion here fairly recently in which utf-16LE was
> >involved, maybe it'll help if you hunt it down.
>
> I went back 3500 messages and found 2 messages that you answered,
> but I did not get any usefull information from them.

The little grey cells are fading, but I'm convinced that I already
said something useful in a thread about utf-16 and the MS train sim
before.  I'm durned if I can put my finger on it again now.

> >Speak out, man!  The PSI::ESP module is on the blink...
>
> I can help you with that :-))
>
> >Are you perhaps looking for join('', @linesengwag1); ?
>
> tried that line, and it too fails after the first line.

But the problem (I think) at this point in your Perl code is that
you're trying to work with utf-16 characters in bytes, which means
that every utf-16 character will need two bytes: but you don't tell
Perl about it, and now and again it looks as if you splice-in the odd
single byte, without Perl realising that it's supposed to be a
double-byte - one of which will likely be zero.  If you were to work
in character mode, that would be taken care of for you (as long as it
doesn't have to be compatible with older Perls, that is).  As you can
tell, I'm strongly in favour of the new way of doing it.

As to programming style, I really can't commend Tad's remarks too
highly: a modular approach based on the actual structure of the
problem can't be beat.  (And I speak as a trained physicist, of whom
it is said "physicists code FORTRAN in any language" - but I try not
to do that!).

I'm sorry if this seems too obtuse an answer, but we've got to start
somewhere, and I'm afraid your existing prog is too much to serve as a
starting point.

good luck


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

Date: Thu, 14 Aug 2003 17:31:04 -0500
From: "H. Nakanishi" <hisao@physics.purdue.edu>
Subject: Re: Question about "eval" security
Message-Id: <bhh2ij$99j$1@mozo.cc.purdue.edu>

Thanks to Randal and Richard for their help. I will use:

$userinput =~ s/\$(\w+)/${$1}/g;

instead. Are there any problems with this?

H. Nakanishi
-----------------------------------------------------------
PS Now, it turns out that what I was going to use, the big, bad "eval
qq...",
actually wouldn't have been so bad where I was going to use it. This is
because I had something like:

$useinput =~ s/(^|[^A-Za-z0-9_\.])([a-zA-Z])/$1\$zzz$2/g;

before the "eval" call (which would have taken air out of "system('rm -rf
/')"
or anything of the sort. Actually, I should really combine this with the
variable substitution above anyway. I guess I am just klutzy.

Thanks again.
------------------------------------------------------------
"H. Nakanishi" <hisao@physics.purdue.edu> wrote in message
news:bhg9u3$oc2$1@mozo.cc.purdue.edu...
> I wish to use "eval" on a user input but want to make sure security is not
> compromised. What I want is just to allow variable interpolation but not
any
> executions. Would something like:
>
> eval qq/"$userinput"/;
>
> work? As far as I could test it, it seems to do the job (i.e., does
evaluate
> any valid variables in $userinput but refuse to execute any commands in
it.
> (If I take the double quotes out, then it would execute commands - which
is
> very bad. I want to make sure that this is OK as far as security.
>
> Thanks in advance.
> H. Nakanishi
>
>




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

Date: Thu, 14 Aug 2003 19:23:02 -0400
From: Chesucat <chesucat@freeshell.org>
Subject: Re: Question about "eval" security
Message-Id: <Pine.NEB.4.33.0308141909290.6762-100000@norge.freeshell.org>

On Thu, 14 Aug 2003, H. Nakanishi wrote:

> Thanks to Randal and Richard for their help. I will use:
>
> $userinput =~ s/\$(\w+)/${$1}/g;
>
> instead. Are there any problems with this?

userinput matches and substitute a dollar and one or more any word to the
end of the string, put one or more any word into variable one and discards
the rest globally.  No!  That make perfect sense to me, but I am just NOT
a perl hacker!;-)

chesucat

-- 
chesucat@sdf.lonestar.org
SDF Public Access UNIX System - http://sdf.lonestar.org
Basic is a high level languish.
APL is a high level anguish.



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

Date: 14 Aug 2003 16:33:57 -0700
From: jwillmore@cyberia.com (James Willmore)
Subject: Re: question about sigtrap!
Message-Id: <e0160815.0308141533.339ffe18@posting.google.com>

> Then I try to use sigtrap to catch the ctrl+c (SIGINT).
> 
> use sigtrap qw(handler mysig_handler normal-signals);
> 
> sub mysig_handler{        
>     my($sig) = @_;
>     print "Caught a SIG$sig--shutting down\n";
>     die "Terminated by user: $!\n";
> }
> 
> however, when I use ctrl+c, I still only kill the child process
> invoked by system, the scripts still continue running.
> 
> Is there any solutions?

I usually use something like:

$SIG{TERM} = $SIG{INT} = sub{warn "Caught an INT\n Exiting ...\n";exit;};

However, there may be issues with this approach.  It may depend on 
what OS you're using as to what signals are issued and trapable.

HTH

Jim


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

Date: Fri, 15 Aug 2003 00:24:55 GMT
From: ktom <abc@nowhere.com>
Subject: question regarding multiple args to sub 
Message-Id: <rLV_a.189850$xg5.71170@twister.austin.rr.com>

I have to subs in which i am attempting to pass multiple args to and i 
have managed to get it to work, after spending all afternoon trying to 
get my brain around it.  I still don't have my brain around and the 
solution seems absurd!!

below are snippets...

1st call:

         &printVec( \@spline, \@indx, \@port1 );
          }

1st working sub:

sub printVec {
#our @spline;
#   my (@spline,@indx,@port) = @_ ;
#   print "pre @$spl, @$indx, @$port\n";
#   print "spline @spline\n";
    my ($spl,$indx,$port) = @_ ;
    my @prt = @$port ;
    my @ndx = @$indx ;
    my @spline = @$spl ;


2nd call:

       &printTset( \@indx, $vect, $cmmnt ) ;
       }

2nd working sub:

sub printTset {
    my ( $indx, $vct, $cmt) = @_ ;
    my @ndx = @$indx;
    my $vect = $vct;
    my $cmmnt = $cmt;

if i don't use the \ on the passed parameters, it seems to merge them 
all into one big array.. blahh.

this seems like a lot of code, seemingly redundant to my wee perl mind, 
to pass values to a subroutine.

what magic am i missing or is this just the way it is???

thanks..



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

Date: 14 Aug 2003 15:56:09 -0700
From: antquinonez@yahoo.com (Antonio Quinonez)
Subject: Re: sort multi-key hash by value and print out with key value pairs
Message-Id: <6f8c5d17.0308141456.6d48252f@posting.google.com>

i'm answering my own question. excuse me. essentially, i take a
multidimensional hash and i make it smaller dimensional.

in case anyone ever cares, again:

foreach $npanxx ( keys %RS ) {

	for $node ( keys %{ $RS{$npanxx} } ) {
		for $plan ( keys %{ $RS{$npanxx}{$node} } ) {
			$newkey = "${node}:${plan}";
			$RT{$npanxx}{$newkey} = $RS{$npanxx}{$node}{$plan};
		}	
	}
}


foreach $npanxx (sort keys %RT){
	for $np (sort {$RT{$npanxx}{$a} <=> $RT{$npanxx}{$b}} keys %{
$RT{$npanxx} }) {
		print "$npanxx :: $np :: $RT{$npanxx}{$np}\n";
#then just break $np into $node and $plan using the split function on
":"
}
	print "\n";
}

thanks for your attention.
aq

antquinonez@yahoo.com (Antonio Quinonez) wrote in message news:<6f8c5d17.0308141018.18e6deaa@posting.google.com>...
> I am trying to sort hash elements with the following structure:
> 
> %hashname{$npanxx}{$node}{$plan} = cost
> 
> so that i get plans ordered by lowest to greatest cost, in the format
> of:
> $npanxx:: $node :: $plan :: cost
> 
> i have the solution for SET 1(see below), where the second key ($node)
> completes the hash member and gives me back what i want. I just can't
> solve for the higher order hash. any help would be appreciated. sample
> data for SET 1 and SET 2 and code for SET 1 follows:
> 
> %RS = ();
> 
> ###SET 1
> $RS{206231}{SEA} = 1.2;
> $RS{206231}{NYC} = 11.2;
> $RS{206231}{LAX} = 4.2;
> $RS{206231}{CHI} = 10.2;
> 
> $RS{206254}{SEA} = 3.2;
> $RS{206254}{NYC} = 11.2;
> $RS{206254}{LAX} = 20.2;
> $RS{206254}{CHI} = 15.2;
> 
> 
> ####SET 2
> $RS{202211}{SEA}{plan_intel} = .2;
> $RS{202211}{NYC}{plan_athlon} = 2;
> $RS{202211}{LAX}{plan_duron} = 3;
> $RS{202211}{CHI}{plan_pentium} = 2.5;
> 
> $RS{202200}{SEA}{plan_intel} =200;
> $RS{202200}{NYC}{plan_athlon} = 20;
> $RS{202200}{LAX}{plan_duron} =50;
> $RS{202200}{CHI}{plan_pentium} = 100;
> 
> 
> #### CODE ###
> print "works for SET 1\n";
> foreach $npanxx (sort keys %RS){
> 	for $node (sort {$RS{$npanxx}{$a} <=> $RS{$npanxx}{$b}} keys %{
> $RS{$npanxx} }) {
> 		print "$npanxx :: $node :: $RS{$npanxx}{$node}\n";
> 	}
>  print "\n";
> }


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

Date: 14 Aug 2003 16:22:22 -0700
From: jwillmore@cyberia.com (James Willmore)
Subject: Re: strange error  "Unsuccessful stat on filename "
Message-Id: <e0160815.0308141522.239b300c@posting.google.com>

> Hi,
> I get such a error
> Unsuccessful stat on filename containing newline at
> /usr/local/lib/perl5/5.8.0/ExtUtils/MM_Unix.pm line 2775
> 
> when i install a module .
> 
> I use HP-UX  IA64
> i wouder does the file  MM_Unix.pm  contains some characters which the HP-UX
> does not recognise or Perl in HP-UX
> does not know.

What module are you trying to install?  How are you installing it?
Have you had trouble installing other modules?

At first glance, it looks like someone may have made a mistake in 
creating the Makefile.PL file for this module.  It may not be Perl 
or the OS that's at fault, but the mdoule.

Jim


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

Date: Thu, 14 Aug 2003 15:58:49 -0700
From: "David Oswald" <spamblock@junkmail.com>
Subject: Re: Suggestions for further perl reading
Message-Id: <vjo55f597jccb5@corp.supernews.com>


"Chad" <chussung@operamail.com> wrote in message
news:97a530bb.0308131640.60c0b7c8@posting.google.com...
> Ok I have finished the Llama book and am now creating simple scripts.
>
> My question is what should I read to further myself at this.  is the
> camel book the way to go or is there something better?
>
> One of my goals(among many) is to be able to streamline my code
> better(what takes me a whole screen would probably take you about 3
> lines).


You'll get a lot of responses to this one.  One common response is that it's
all in the perldocs, perlfaqs, perltuts, and Perl-related websites (such as
www.perlmonks.org).  I agree that much can be learned online at little or no
cost.  However, I am one of those people who likes to be able to sit down
with the book and read, contemplate, and then return to the computer to
experiment.  For that reason, I've accumulated some Perl books, and found a
few good ones along the way.

The Llama book, as you've discovered, is a good starting point.  It leaves a
lot of unanswered questions for someone who wishes to dig deeper, but it
goes a long way toward getting you started.

The Camel book is a good quick reference for me, especially when I'm
thinking through a problem away from the keyboard.  Even at the keyboard
sometimes it's easier for me to flip a few pages than scan through online
documentation.  Everyone feels differently about this subject, but for me, I
like to flip into the book.

The Owls book (Mastering Regular Expressions) will teach you everything you
wanted to know about Regular Expressions, and more.  If you read it over the
course of just a few days, all at once, you'll find yourself thinking about
how to write a Reg Exp to match what you're ordering as you sit in the
drive-through at McDonalds.  It tends to modify your way of thinking for
awhile while your mind absorbs it.  I think it's a great resource.

And the Perl Cookbook is also fantastic.  One can learn the syntax of the
language, and think through problems on his own, but sometimes when one sees
it in a book like the Perl Cookbook, new, more efficient, more legible, more
Perl-ish ways of doing things can be discovered.

Dave




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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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.  

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


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