[23642] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5849 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 24 00:07:49 2003

Date: Sun, 23 Nov 2003 21:05:07 -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           Sun, 23 Nov 2003     Volume: 10 Number: 5849

Today's topics:
    Re: Avoiding running a process twice <Jodyman@hotmail.com>
    Re: Avoiding running a process twice (Sam Holden)
        clarification on comment <bxtrap01@comcast.net>
    Re: code structure <pinyaj@rpi.edu>
    Re: from data file into hash slice <noreply@gunnar.cc>
    Re: if action do same action plus... <REMOVEsdnCAPS@comcast.net>
    Re: if action do same action plus... (Malcolm Dew-Jones)
        Newbie question - calling perl from html <charles_dunhill@postmaster.co.uk>
    Re: Newbie question - calling perl from html <asu1@c-o-r-n-e-l-l.edu>
    Re: Newbie question - calling perl from html <mail@dytron.demon.co.uk>
    Re: Newbie question - calling perl from html <invalid-email@rochester.rr.com>
    Re: newbie regular expression questions <bxtrap01@comcast.net>
    Re: newbie regular expression questions <noreply@gunnar.cc>
    Re: newbie regular expression questions <asu1@c-o-r-n-e-l-l.edu>
    Re: newbie regular expression questions <bxtrap01@comcast.net>
    Re: newbie regular expression questions (Malcolm Dew-Jones)
    Re: newbie regular expression questions (Tad McClellan)
    Re: newbie regular expression questions (Sam Holden)
    Re: push @arr, slice-of-href <pinyaj@rpi.edu>
    Re: reading and writing to text file via form newbie <me@privacy.net>
    Re: reading and writing to text file via form newbie <noreply@gunnar.cc>
        sending stdin to a shell command in perl (Andrew)
    Re: sending stdin to a shell command in perl (Tad McClellan)
        why does Perl choke here? <noemail@none.com1>
    Re: why does Perl choke here? <noreply@gunnar.cc>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 23 Nov 2003 23:34:11 GMT
From: "Jodyman" <Jodyman@hotmail.com>
Subject: Re: Avoiding running a process twice
Message-Id: <Ttbwb.17137$Rk5.1854@newsread1.news.atl.earthlink.net>

"Ed W" <dodgynewsgroups@ewildgoose.demon.co.uk> wrote in message
news:HuLvb.514884$be.71024@news.easynews.com...

[snip]

> how to avoid
> allowing the user to run multiple instances of my app.  I'm looking for
> something cross platform, Win32 and linux.

[snip]

Ed,  Here's what I use checking for new virus dat files at NAI:

# Set flag file to see if process is already running
$flagfile = "c:/test/virusflagfile";

# Check to see if process is already running
if (!-e $flagfile ) { &createflag;  # If it doesn't exist, create one

        # Do your processes HERE!!!!!!!!!!!

        # Clear flag file so process can run again
        &deleteflag;}

# If this process is already running - Exit
else { exit; }

sub createflag {
 open (FLAG,">>$flagfile") or die "Can't open $flagfile: $!\n";
}

sub deleteflag {
 close (FLAG) or die "Can't close $flagfile: $!\n";
 unlink $flagfile;
}




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

Date: 23 Nov 2003 23:44:43 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Avoiding running a process twice
Message-Id: <slrnbs2hjb.1do.sholden@flexal.cs.usyd.edu.au>

On Sun, 23 Nov 2003 23:34:11 GMT, Jodyman <Jodyman@hotmail.com> wrote:
> "Ed W" <dodgynewsgroups@ewildgoose.demon.co.uk> wrote in message
> news:HuLvb.514884$be.71024@news.easynews.com...
> 
> [snip]
> 
>> how to avoid
>> allowing the user to run multiple instances of my app.  I'm looking for
>> something cross platform, Win32 and linux.
> 
> [snip]
> 
> Ed,  Here's what I use checking for new virus dat files at NAI:
> 
> # Set flag file to see if process is already running
> $flagfile = "c:/test/virusflagfile";

That certainly is not cross platform. Unless you have a very strange linux
file system with c:/test existing in all directories.

> 
> # Check to see if process is already running
> if (!-e $flagfile ) { &createflag;  # If it doesn't exist, create one

There's an obvious race condition there. So the technique doesn't
stop multiple instances running at once.


> 
>         # Do your processes HERE!!!!!!!!!!!
> 
>         # Clear flag file so process can run again
>         &deleteflag;}

And what happens if the process is terminated some how (the power cord is
kicked out of the machine, for example) before it executes deleteflag?
So the technique will also stop any instance running...

This seems an amazingly bad way of doing job.
 
> # If this process is already running - Exit
> else { exit; }
> 
> sub createflag {
>  open (FLAG,">>$flagfile") or die "Can't open $flagfile: $!\n";
> }
> 
> sub deleteflag {
>  close (FLAG) or die "Can't close $flagfile: $!\n";
>  unlink $flagfile;
> }

And why are you using &createflag, instead of createflag()? You
certainly don't seem to use the current @_ in the subroutine?

-- 
Sam Holden


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

Date: Mon, 24 Nov 2003 04:17:21 GMT
From: "bbxrider" <bxtrap01@comcast.net>
Subject: clarification on comment
Message-Id: <lDfwb.215071$mZ5.1626135@attbi_s54>

i would apologize based on your request because i appreciate your thoughtful
and helpful replies
and that engenders my respect for your opinions as well
perhaps i should have stated my dilema that 'it seems to work from the
testing i have done', instead of 'i know it works'
because i did test the code as best i thought and am confused by the
results, i always try to find answers first from my manuals and
then google
as far as coding  and testing i think we all come to understand how it works
from both its stated functionality
in documentation and actual testing, i'm new to perl but there are other
languages that i programmed in
for years and still am learing subtle things about even the most common
syntax, functions etc., the point being
we are not perfect, sometimes there is more than we think we know, and
sometimes we seek the help of
others when at a dead end
but thats why i post questions in a forum such as this, obviously if i
understood the code i wouldn't be
asking the question!
i can't know the exact motivation of tintin's comments and if i
misintrepeted, i regret that.
the extent and tone of his reply, solely as written, seems to be questioning
my right to even ask the question
it has a sarcastic tone and it seems to be scolding or demeaning, if thats
all somebody has to say without
any hint of 'maybe you should try this or read this, etc' then i can only
assume they have not other motivation
other than negativity.

From: "Gunnar Hjalmarsson" <noreply@gunnar.cc>
Subject: Re: newbie regular expression questions
Date: Sunday, November 23, 2003 5:31 PM

bbxrider wrote:
> thanks for all the help, except from tintin, if thats your idea of
> help please just keep it to yourself, it certainly doesn't do
> anybody any good

Tintin's comment was not unhelpful, it was justified, and you really
ought to find it worth considering. IMHO you owe him an apology.

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





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

Date: Sun, 23 Nov 2003 20:13:01 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: code structure
Message-Id: <Pine.SGI.3.96.1031123200959.10741B-100000@vcmr-64.server.rpi.edu>

On Sun, 23 Nov 2003, Edo wrote:

>>   sub load ($\%);
>>   sub prepare (\%\%);
>> 
>> foreach my $item ( @things ) {
>>     tie my (%data), 'Tie::IxHash';
>>     load ($item => %data); # %data will automatically become \%data
>> 
>>     tie my (%info), 'Tie::IxHash';
>>     prepare (%data => %info);  # automatically referenced
>> 
>>     print Dumper %info;
>> }
>> 
>> sub load ($\%) {
>>     my ($i, $d) = @_;
>>     my $key = (split /,/,$i)[1];
>>     push @{$data{$key}}, $_;

You're not using 'strict'.  If you were, you'd be told that %data wasn't
ever declared.

  sub load ($\%) {
    my ($i, $d) = @_;
    my $key = (split /,/, $i)[1];
    push @{ $d->{$key} }, ???;
  }

I have ??? there, because I have no idea what $_ is supposed to be.  You
want to use $d, not %data, and to work with a hash ref, you need to
dereference it in some way.  I've done $d->{$key}, but you could also do
$$d{$key}.

>>     return %data;

These functions DON'T need to return anything.

>> }
>> 
>> sub prepare (\%\%) {
>>     my ($data, $info) = @_;
>>     foreach my $key ( keys %data ) {
>>         my $val = ...code
>>         $info{$date} = $value;
>>      }
>>     return %info;

Same issues here.

>> }

-- 
Jeff Pinyan            RPI Acacia Brother #734            2003 Rush Chairman
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: Mon, 24 Nov 2003 00:55:59 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: from data file into hash slice
Message-Id: <bprhou$1mnoun$1@ID-184292.news.uni-berlin.de>

Edo wrote:
> I need to grap a few lines of records from a comma delimited data
> file, the second field is the key and the rest of the line to the
> right of the key are the data associated with this key.
> 
> open FH, "/dir/.../file.txt" or die $!,"\n";
> tie my (%all), 'Tie::IxHash';
> put the file into %all;
> tie my (%section), 'Tie::IxHash';
> 
> while (<FH>){
>     get the 20 records from %all starting from the 'n' record
>     or from key 'x' into a sorted hash %section

"Or"? I don't understand which 20 records it is you actually want to
select.

>     }
> 
> how can it be done?

By first structuring the problem and then writing code that does the
needed steps, dealing with one thing at a time while studying the
applicable docs.

I played with a partial solution. I wrote a function for grabbing a
selection of records:

     sub selection {
         my ($file, $start) = @_;
         my %records = ();
         open FH, $file or die $!;
         while (<FH>) {
             next if $. < $start;
             my @fields = split /,/;
             $records{ $fields[1] } = [ splice @fields, 2 ];
             last if $. == $start + 19;
         }
         close FH or die $!;
         return map { $_, $records{$_} } sort keys %records;
     }

     my @sortedrecords = selection('file.txt', 3);

@sortedrecords now contains 20 pairs of keys and array references
representing line 3-22, where the pairs are sorted by key, and the
references are references to anonymous arrays with the data.

The array can be assigned to a hash:

     my %hash = @sortedrecords;

and to access e.g. the first data value associated with 'key 3' you
can do:

     print $hash{'key 3'}[0];

Maybe the above is of some help.

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



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

Date: Sun, 23 Nov 2003 22:02:54 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: if action do same action plus...
Message-Id: <Xns943CEA9A12FC7sdn.comcast@216.196.97.136>

Edo <eddhig22@yahoo.com> wrote in news:3FC10C1C.9090603@yahoo.com:

> sorry, it is check( \@arr1, \@arr2 ) is calculated twice, how to make 
> the code more effecient.

Store the result of check(...) in a temporary variable before the if() 
block.

-- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print


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

Date: 23 Nov 2003 20:18:46 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: if action do same action plus...
Message-Id: <3fc186a6@news.victoria.tc.ca>

Edo (eddhig22@yahoo.com) wrote:
: A. Sinan Unur wrote:
: > Edo <eddhig22@yahoo.com> wrote in news:3FC0FEED.6020808@yahoo.com:
: > 
: > 
: >>Hello
: >>not sure if the title is correct but after some reading, I could not 
: >>find the answer
: > 
: > 
: > what is the question?
: > 
: > 
: >>     if ( check( \@arr1, \@arr2 ) > ( sort {$a <=> $b} @top3 )[0]){
: >>     push @top3, check (\@arr1, \@arr2);
: >>     }
: >>
: >>sub check {
: >>     ...
: >>     returns a number
: >>}
: >>
: >>thanks
: > 
: > 
: > you are welcome.
: > 
: > Sinan.

: sorry, it is check( \@arr1, \@arr2 ) is calculated twice, how to make 
: the code more effecient.

perhaps

	my $checked = check( \@arr1, \@arr2 );
	if ($checked > ...etc...
	{  push ... , $checked;




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

Date: Mon, 24 Nov 2003 01:22:12 GMT
From: Charles <charles_dunhill@postmaster.co.uk>
Subject: Newbie question - calling perl from html
Message-Id: <9bWfnsLu0Vw$EwSa@blueyonder.co.uk>

Hi there.

This is probably the most basic of all questions, and I've looked at 
various scripts which show how to do it (such as counters, time displays 
etc) and online resources to get an answer, but my version still won't 
work even though I'm using the same commands.  I would be grateful if 
someone could point me in the right direction before I tear my hair out!

All I want to do, and I'm doing this so I can learn how to use perl, is 
display some text on a static web page.

I have index.html with the following

<html>
<body>
<p>This is some text</p>
<p><script src="../cgi-bin/hello.cgi"></script></p>
</body>
</html>

I have hello.cgi with the following (permissions are 755)

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello.  Thanks for dropping by\n";

But all the web page shows is:

This is some text

I've changed the src to the complete address but it still doesn't work. 
Has anyone got any ideas on what I'm doing wrong?

Thanks in advance and I'm really sorry if this is so dumb, but I am 
trying to learn as fast as I can.

Cheers!
-- 
Charles


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

Date: 24 Nov 2003 02:06:10 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Newbie question - calling perl from html
Message-Id: <Xns943CD6ACEE6D7asu1cornelledu@132.236.56.8>

Charles <charles_dunhill@postmaster.co.uk> wrote in news:9bWfnsLu0Vw
$EwSa@blueyonder.co.uk:

> Hi there.
> 
> This is probably the most basic of all questions, and I've looked at 
> various scripts which show how to do it (such as counters, time 
> displays etc) and online resources to get an answer, but my version 
> still won't work even though I'm using the same commands.  

commands won't same my but version even work though

> I would be grateful if someone could point me in the right direction 
> before I tear my hair out!

It seems like you Javascript, server side includes, and CGI are somehow 
jumpled up together in your brain. 

> I am trying to learn as fast as I can.

Slow down and learn each tool (concept, whatever) separately.

Sinan.

-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


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

Date: Mon, 24 Nov 2003 02:26:41 -0000
From: "Leigh" <mail@dytron.demon.co.uk>
Subject: Re: Newbie question - calling perl from html
Message-Id: <bprqcs$5j$1$8300dec7@news.demon.co.uk>


"Charles" <charles_dunhill@postmaster.co.uk> wrote in message
news:9bWfnsLu0Vw$EwSa@blueyonder.co.uk...
> Hi there.
>
> This is probably the most basic of all questions, and I've looked at
> various scripts which show how to do it (such as counters, time displays
> etc) and online resources to get an answer, but my version still won't
> work even though I'm using the same commands.  I would be grateful if
> someone could point me in the right direction before I tear my hair out!
>
> All I want to do, and I'm doing this so I can learn how to use perl, is
> display some text on a static web page.
>
> I have index.html with the following
>
> <html>
> <body>
> <p>This is some text</p>
> <p><script src="../cgi-bin/hello.cgi"></script></p>
> </body>
> </html>
>
> I have hello.cgi with the following (permissions are 755)
>
> #!/usr/bin/perl
> print "Content-type: text/html\n\n";
> print "Hello.  Thanks for dropping by\n";
>
> But all the web page shows is:
>
> This is some text
>
> I've changed the src to the complete address but it still doesn't work.
> Has anyone got any ideas on what I'm doing wrong?
>
> Thanks in advance and I'm really sorry if this is so dumb, but I am
> trying to learn as fast as I can.
>
> Cheers!
> -- 
> Charles

Charles,

You can turn your text string into a link to call your Perl script thus:

<html>
<body>
<p><a href="../cgi-bin/hello.cgi">This is some text</a></p>
</body>
</html>

Note the use of the anchor tag <a>. You use the <script> tag to add code at
the client (browser), not the server. It should help you get started. Good
luck.

Cheers,

Leigh.




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

Date: Mon, 24 Nov 2003 03:48:54 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Newbie question - calling perl from html
Message-Id: <3FC17EA8.50406@rochester.rr.com>

Charles wrote:

 ...
> This is probably the most basic of all questions, and I've looked at 
> various scripts which show how to do it (such as counters, time displays 
> etc) and online resources to get an answer, but my version still won't 
> work even though I'm using the same commands.  I would be grateful if 
> someone could point me in the right direction before I tear my hair out!
> 
> All I want to do, and I'm doing this so I can learn how to use perl, is 
> display some text on a static web page.
> 
> I have index.html with the following
> 
> <html>
> <body>
> <p>This is some text</p>
> <p><script src="../cgi-bin/hello.cgi"></script></p>


I think you've got Perl confused with JavaScript.  JavaScript is a 
feature of most every web browser these days; Perl is not.  JavaScript 
runs in the client's web browser.  Your Perl script is a CGI script 
which runs on your web server, not the client's machine.  To access a 
CGI script from your HTML, you will need to include one or more links in 
your HTML (usually with either the <a href="../cgi-bin/hello.cgi"> link 
text </a> or a form with a submit button.  When the user clicks your 
link or button, your CGI script will run on your server, and its output 
will go back to the user's browser.  One other thing you can do is have 
the user input the URL of your CGI script directly, as in perhaps 
something like http://www.whatever.com/cgi-bin/hello.cgi .

There is also something called PerlScript, but usually it also runs on 
the web server and not the client's computer, and only on certain less 
desirable OS's and web servers (I don't know much about it).  It looks 
like PerlScript can also run on the client side, but only if it is 
installed there (in general, it won't be), and only on certain 
undesirable OS's and browers.

Note that you should probably be very cautious about installing 
PerlScript as part of your web browser -- it is probably much much less 
secure that JavaScript, since Perl is a much more general language, with 
access to lots more of your computer than JavaScript has.  I would never 
want a PerlScript script from an untrusted site to run on my computer.


> </body>
> </html>


 ...


Note that CGI setup issues are off-topic for this newsgroup (the issues 
would be the same if the CGI program were written in C , sh, befunge or 
whatever).  If you have trouble with CGI, follow everything in:

    perldoc -q 500

and then try comp.infosys.www.authoring.cgi .  If you have trouble with 
Perl, this is the place.

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



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

Date: Mon, 24 Nov 2003 00:34:49 GMT
From: "bbxrider" <bxtrap01@comcast.net>
Subject: Re: newbie regular expression questions
Message-Id: <Jmcwb.287471$Tr4.898822@attbi_s03>

thanks for all the help, except from tintin, if thats your idea of help
please just keep it to yourself, it certainly doesn't do anybody any good
however am still struggling with this please see new post
under newbie processing form input question

"bbxrider" <bxtrap01@comcast.net> wrote in message
news:ZqRvb.280961$Fm2.290586@attbi_s04...
> i' ve found this code for parsing form input
>  foreach (split(/[&;]/, $buffer)) {
>         s/\+/ /g ;
>         ($name, $value)= split('=', $_, 2) ;
>         $name=~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge ;
>         $value=~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge ;
>         ..........
> i know it works but the data is ascii characters to begin with and don't
> understand what is the need for the substitution after converting all the
> +'s to spaces??
> i know am cycling thru the input field names and their values character by
> character for searching for only digits and upper+lower case alphabet
> to substitute but
> don't understand significance of the % sign,
> not really sure what the {2} grouping is doing
> and basically it seems to be saying look for ascii digits and alphabet and
> convert the hex value of those characters to the same value as starting
> with, in other words, convert the original value back to the original
> value????????
> is type of conversion only necessary due to properties of form input data
on
> the web????
>
>




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

Date: Mon, 24 Nov 2003 02:31:18 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: newbie regular expression questions
Message-Id: <bprnc4$1rp3ov$1@ID-184292.news.uni-berlin.de>

bbxrider wrote:
> thanks for all the help, except from tintin, if thats your idea of
> help please just keep it to yourself, it certainly doesn't do
> anybody any good

Tintin's comment was not unhelpful, it was justified, and you really
ought to find it worth considering. IMHO you owe him an apology.

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



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

Date: 24 Nov 2003 02:09:51 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: newbie regular expression questions
Message-Id: <Xns943CD74CC110Basu1cornelledu@132.236.56.8>

"bbxrider" <bxtrap01@comcast.net> wrote in
news:Jmcwb.287471$Tr4.898822@attbi_s03: 

> thanks for all the help, except from tintin, if thats your idea of
> help please just keep it to yourself, it certainly doesn't do anybody
> any good however am still struggling with this please see new post
> under newbie processing form input question
> 
> "bbxrider" <bxtrap01@comcast.net> wrote in message
> news:ZqRvb.280961$Fm2.290586@attbi_s04...

Do not top-post.

Do read the posting guidelines posted here regularly and follow them.

Do use Google to locate the CGI specs and read them.

Sinan.

-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


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

Date: Mon, 24 Nov 2003 04:15:51 GMT
From: "bbxrider" <bxtrap01@comcast.net>
Subject: Re: newbie regular expression questions
Message-Id: <WBfwb.219153$275.824455@attbi_s53>

gunnar,
i would apologize based on your request because i appreciate your thoughtful
and helpful replies
and that engenders my respect for your opinions as well
perhaps i should have stated my dilema that 'it seems to work from the
testing i have done', instead of 'i know it works'
because i did test the code as best i thought and am confused by the
results, i always try to find answers first from my manuals and
then google
as far as coding  and testing i think we all come to understand how it works
from both its stated functionality
in documentation and actual testing, i'm new to perl but there are other
languages that i programmed in
for years and still am learing subtle things about even the most common
syntax, functions etc., the point being
we are not perfect, sometimes there is more than we think we know, and
sometimes we seek the help of
others when at a dead end
but thats why i post questions in a forum such as this, obviously if i
understood the code i wouldn't be
asking the question!
i can't know the exact motivation of tintin's comments and if i
misintrepeted, i regret that.
the extent and tone of his reply, solely as written, in IMHO seems to be
questioning
my right to even ask the question
it has a sarcastic tone and it seems to be scolding or demeaning, if thats
all somebody has to say without
any hint of 'maybe you should try this or read this, etc' then i can only
assume they have no real motivation to help.

"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:bprnc4$1rp3ov$1@ID-184292.news.uni-berlin.de...
> bbxrider wrote:
> > thanks for all the help, except from tintin, if thats your idea of
> > help please just keep it to yourself, it certainly doesn't do
> > anybody any good
>
> Tintin's comment was not unhelpful, it was justified, and you really
> ought to find it worth considering. IMHO you owe him an apology.
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl
>




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

Date: 23 Nov 2003 20:15:51 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: newbie regular expression questions
Message-Id: <3fc185f7@news.victoria.tc.ca>

Tintin (me@privacy.net) wrote:

: "bbxrider" <bxtrap01@comcast.net> wrote in message
: news:ZqRvb.280961$Fm2.290586@attbi_s04...
: > i' ve found this code for parsing form input
: >  foreach (split(/[&;]/, $buffer)) {
: >         s/\+/ /g ;
: >         ($name, $value)= split('=', $_, 2) ;
: >         $name=~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge ;
: >         $value=~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge ;
: >         ..........
: > i know it works

: Do you really?  How do you know it works if you don't fully understand the
: code?

I know my car works, but I don't fully understand it.

I know my java compiler works but I understand that much less.

I haven't looked at the internal details of CGI.PM in ages, I don't
remember most of its documentation, I forget the _exact_ significance of
the qw(:standard) that I prefer over the object interface, I have never
bothered to figured out certain features that I haven't found the need to
use based on a high level description - but never the less I am pretty
sure it works, and would certainly recommend it over the above code which
I think I do understand pretty well.



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

Date: Sun, 23 Nov 2003 22:09:35 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: newbie regular expression questions
Message-Id: <slrnbs313v.ooh.tadmc@magna.augustmail.com>

bbxrider <bxtrap01@comcast.net> wrote:

> thanks for all the help, except from 


So long then.


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


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

Date: 24 Nov 2003 04:54:52 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: newbie regular expression questions
Message-Id: <slrnbs33or.581.sholden@flexal.cs.usyd.edu.au>

On 23 Nov 2003 20:15:51 -0800,
	Malcolm Dew-Jones <yf110@vtn1.victoria.tc.ca> wrote:
> Tintin (me@privacy.net) wrote:
> 
>: "bbxrider" <bxtrap01@comcast.net> wrote in message
>: news:ZqRvb.280961$Fm2.290586@attbi_s04...
>: > i' ve found this code for parsing form input
>: >  foreach (split(/[&;]/, $buffer)) {
>: >         s/\+/ /g ;
>: >         ($name, $value)= split('=', $_, 2) ;
>: >         $name=~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge ;
>: >         $value=~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge ;
>: >         ..........
>: > i know it works
> 
>: Do you really?  How do you know it works if you don't fully understand the
>: code?
> 
> I know my car works, but I don't fully understand it.

Only because your car was designed and built by people you trust did
it correctly, complying with relevant safety and operating standards.
And it hasn't failed any of the tests you have tried with it.

Would you trust a car I built out of cardboard and rubberbands? 
What if it drove around the block once without any problems?

> 
> I know my java compiler works but I understand that much less.

Only because you trust the author of the compiler understood how
it works and that it hasn't failed to produce correct output yet.
 
> I haven't looked at the internal details of CGI.PM in ages, I don't
> remember most of its documentation, I forget the _exact_ significance of
> the qw(:standard) that I prefer over the object interface, I have never
> bothered to figured out certain features that I haven't found the need to
> use based on a high level description - but never the less I am pretty
> sure it works, and would certainly recommend it over the above code which
> I think I do understand pretty well.

Only because it has been widely tested and found to work.

Whereas code which has been "found" shouldn't be so trusted, and hence
without understanding the code you can't declare that "i know it works".
If other people who do understand how it works have declared
that "it works" then you could make such a declaration, if you trust
their judgement and knowledge.

If the code was written by someone you trust it's a different story,
but if it is code randomly found on the internet that usually isn't
the case.

-- 
Sam Holden


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

Date: Sun, 23 Nov 2003 21:04:55 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: push @arr, slice-of-href
Message-Id: <Pine.SGI.3.96.1031123205845.11226B-100000@vcmr-64.server.rpi.edu>

On Mon, 24 Nov 2003, Edo wrote:

>sub scan (\@\%) {
>     my ($arr, $hash) = @_;
>     my @k = keys %$hash;

Should you add

  my @top3;

here?

>     for( 0 .. keys(%$hash) - @$arr+0 ) {

You could have written:

  for (0 .. (@k - @$arr)) { ... }

>	my @v = @hash{ (keys %hash)[ $_ .. $_+2 ] };

You're using %hash here, not %$hash; also, you've already GOT the keys
from %$hash in @k, so don't keep build the list of keys each time through
the list.

  my @v = @$hash{ @k[$_ .. $_+2] };

>	if ( check( \@arr, \@v ) > ( sort {$a <=> $b} @top3 )[0]){
>	    push @top3, href with the %$hash keys and values

  push @top3, { %$hash };

Or do you want to do:

  my %set_of_three;
  @set_of_three{@k} = @v;
  push @top3, \%set_of_three;

>	    }	
>     }
>} 

Half of these are suggestions, have aren't.

-- 
Jeff Pinyan            RPI Acacia Brother #734            2003 Rush Chairman
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: Mon, 24 Nov 2003 00:49:08 -0000
From: Trotsky <me@privacy.net>
Subject: Re: reading and writing to text file via form newbie
Message-Id: <MPG.1a2b65db5d1c313a989681@news.ispserve.co.uk>

Didnt know about the no posting faux pas. Sorry
Its Just that I decided what I needed to do, and am trying to figure out 
how to do it.
I find the best way is to Jump in at the deep end. Sink or Swim. And I 
like to learn as I am doing. The Tutorials online are either the 'Hello 
World' type or extremely complex, nothing in between. But ill keep 
plugging away until I can do it.
If you want to reccommend a tutorial please feel free to.
Cheers John

> 


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

Date: Mon, 24 Nov 2003 02:22:50 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: reading and writing to text file via form newbie
Message-Id: <bprms7$1r4lv2$1@ID-184292.news.uni-berlin.de>

Trotsky wrote:
> Didnt know about the no posting faux pas. Sorry

Well, that was my reaction to your way of presenting your code.

Please keep in mind that this group is primarily for _discussing_ the
Perl programming language. Well defined questions about Perl are also
welcome - the answers to them may be helpful also to others besides
the persons who asked.

At the same time, posts basically saying "I found this (bad) code
somewhere on the web, and it doesn't work, please help me fix it" will
probably not be answered, at least not in the way the person who asked
had expected... People who ask questions are expected to have made
reasonable own efforts to solve their problems by help of e.g. the
Perl documentation and the Perl FAQ before asking for help.

> I find the best way is to Jump in at the deep end. Sink or Swim.
> And I like to learn as I am doing.

I understand that learning style, I have practiced it a lot. :)
However, it does not fit very well as a base for posting questions to
technical Usenet groups.

> The Tutorials online are either the 'Hello World' type or extremely
> complex, nothing in between. But ill keep plugging away until I can
> do it.
> If you want to reccommend a tutorial please feel free to.

I have no personal favorite. This URL may be useful:
http://cgi.resourceindex.com/Documentation/CGI_Tutorials/

However, as regards learning to understand how a piece of code works,
you need to know how to use the Perl documentation. If you have
installed Perl on your computer (which you really should do if you
haven't already), you have the whole documentation on your hard disk.
It's also available on line, e.g. at http://www.perldoc.com/. The FAQ
about CGI may be of special interest to you:
http://www.perldoc.com/perl5.8.0/pod/perlfaq9.html

Good luck!

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



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

Date: 23 Nov 2003 18:53:35 -0800
From: myfam@surfeu.fi (Andrew)
Subject: sending stdin to a shell command in perl
Message-Id: <c5826e91.0311231853.4abae510@posting.google.com>

Hi,
in my simple perl script I have to send string to stdin of an
excutable binary which I run from perl. So I am doing the following:

e.g.

my ($result) = `echo "this will be sent to command" | ./command 2>&1`;
# process result...

is there more elegant way to send to command's stdin without using
echo?

Thanks
Andrei


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

Date: Sun, 23 Nov 2003 22:10:57 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: sending stdin to a shell command in perl
Message-Id: <slrnbs316h.ooh.tadmc@magna.augustmail.com>

Andrew <myfam@surfeu.fi> wrote:

> in my simple perl script I have to send string to stdin of an
> excutable binary which I run from perl.


    perldoc perlopentut

    perldoc -f open


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


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

Date: Mon, 24 Nov 2003 02:25:47 GMT
From: "Z. M. Wu" <noemail@none.com1>
Subject: why does Perl choke here?
Message-Id: <L_dwb.11060$b91.3689@nwrddc01.gnilink.net>

Perl does not like if $other contains special characters
like * ] in the following

my @a=split/$other/,$req;


My current workaround is

$other=~ s/[\)\(\*]/_/g;
$req=~ s/[\)\(\*]/_/g;

before the split.

Any insight or better solution would be helpful

Thanks

Mr Wu Zong Ming



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

Date: Mon, 24 Nov 2003 03:27:11 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: why does Perl choke here?
Message-Id: <bprqku$1qcgv3$1@ID-184292.news.uni-berlin.de>

Z. M. Wu wrote:
> Perl does not like if $other contains special characters
> like * ] in the following
> 
> my @a=split/$other/,$req;

No, they are special characters in regular expressions, and need to be 
escaped.

> My current workaround is
> 
> $other=~ s/[\)\(\*]/_/g;
> $req=~ s/[\)\(\*]/_/g;
> 
> before the split.
> 
> Any insight or better solution would be helpful

Better solution:

     my @a = split /\Q$other/, $req;

See "perldoc perlre".

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



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

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


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