[13198] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 608 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 21 03:07:27 1999

Date: Sat, 21 Aug 1999 00:05:25 -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           Sat, 21 Aug 1999     Volume: 9 Number: 608

Today's topics:
        **** pack() function  <hacker@downcity.net>
    Re: Attn: CRAP (was Re: voting system pealse advise) (Larry Rosler)
    Re: Finding the last occurance of a match/reg exp <kistler@fnmail.com>
    Re: Mail Script Question (Bill Moseley)
    Re: Maintaining User Sessions without Cookies <arunas@an!m.org>
    Re: modules not located in /usr/lib/perl5 <nead@neadwerx.com>
    Re: Newbie : tr/// question (JustYaz)
    Re: newbie CGI question re CGI.pm (Larry Rosler)
        packing raw IP packet <bennycc@pacific.net.sg>
    Re: processing html on the fly part 2 <cw@dwc.ch>
    Re: Recursing through directory headache (Sean McAfee)
    Re: Recursing through directory headache (Ilya Zakharevich)
    Re: Recursing through directory headache (Sean McAfee)
    Re: Recursing through directory headache (Ilya Zakharevich)
    Re: Regular Expression woes <bwalton@rochester.rr.com>
    Re: Regular Expression woes (Bill Moseley)
    Re: Regular Expression woes <kistler@fnmail.com>
    Re: Shell vs Perl (Neko)
    Re: Shell vs Perl (Randal L. Schwartz)
        Syntax of format (NJPin)
    Re: Syntax of format (Sam Holden)
    Re: The real reason people don't use CGI.pm (elephant)
        Time as per IST?? <skumar@deutech.com>
        Using System Or Exec from a perl script <wael@ieee.org>
    Re: Using System Or Exec from a perl script <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: Fri, 20 Aug 1999 23:57:16 -0400
From: "David A. Desrosiers" <hacker@downcity.net>
Subject: **** pack() function 
Message-Id: <Pine.LNX.4.10.9908202355560.29156-100000@broccoli.geek.box>


	I need to replace this function with it's equivalent in pack().
Any ideas? 

--------------------------------------------
function createSessionTable()
{
  cache = HOME "/cache/9"

  printf("%c%c",0,0) > cache  # History.firstDocument
  printf("%c%c",0,0) >> cache # History.lastDocument
  printf("%c%c",0,0) >> cache # History.currentDocument
  printf("%c%c",0,0) >> cache # History.addHistory
  printf("%c%c",0,1) >> cache # History.documents[0] = HOMEPAGEDOCUMENTID

  for (count = 1; count < 32; count++)
    printf("%c%c",0,0) >> cache
  close(cache)
}
--------------------------------------------



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

Date: Fri, 20 Aug 1999 22:18:17 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Attn: CRAP (was Re: voting system pealse advise)
Message-Id: <MPG.1227d66e9f4b3c9f989e8d@nntp.hpl.hp.com>

In article <7pku8i$ijt$1@216.39.141.200> on 21 Aug 1999 01:09:38 GMT, 
Neko <tgy@chocobo.org> says...
+ On Fri, 20 Aug 1999 16:03:23 -0700, lr@hpl.hp.com (Larry Rosler) 
wrote:
+ >In article <7pkivn$32p$1@216.39.141.200> on 20 Aug 1999 21:57:11 GMT, 
+ >Neko <tgy@chocobo.org> says...
+ >> On 20 Aug 1999 08:08:55 GMT, sholden@pgrad.cs.usyd.edu.au (Sam 
Holden) wrote:
+ >> >On Fri, 20 Aug 1999 00:49:36 -0700, Larry Rosler <lr@hpl.hp.com> 
wrote:
+ >...
+ >> >>  ({
+ >> >>	add_topic	=>	\&add_topic,
+ >> >> 	showvote	=>	\&showvote,
+ >> >> 	others	=>	\&others,
+ >> >> 	vote		=>	\&vote,
+ >> >> 	results	=>	\&results,
+ >> >> 	delete	=>	\&delete,
+ >> >>  }->{$FORM{action})->();
+ >> >
+ >> >eval "&$FORM{action}()";
+ >> >
+ >> >Why use a hash when you have got the symbol table I say ;)
+ >> 
+ >> Or if the prospect of running unknown code through eval() scares
+ >> you:
+ >> 
+ >>    $FORM{action}->();
+ >
+ >At least the 'eval' form makes it through "use strict 'refs';"
+ 
+ Do you really believe passing 'use strict' but failing -T is better
+ than the reverse?  Especially in this case where it is a CGI script?

Neither is acceptable.  That's why the dispatch table is a sounder 
solution.

+ >And both of these approaches assume that the names of the subroutines 
+ >are the same as the values of $FORM{action}, which isn't necessary in 
+ >general.
+ 
+ The hash dispatch does likewise.  It blindly assumes that
+ $FORM{action} is the name of a hash key, which also isn't necessary in
+ general.  The real difference is that the hash will let you limit what
+ code will run -- not all subroutines are up for grabs.

I quite agree.  Properly written code would deal with the failure case.

 ({
	add_topic	=>	\&add_topic,
 ...
	delete	=>	\&delete,
 }->{$FORM{action} or die "Unrecognized subroutine.\n"})->();

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sat, 21 Aug 1999 01:55:14 +0200
From: Per Kistler <kistler@fnmail.com>
Subject: Re: Finding the last occurance of a match/reg exp
Message-Id: <37BDEAE2.23F1950B@fnmail.com>

marcza@my-deja.com wrote:
> $string = "One table two table three table forth table";
> while ($string =~ /(\w+)\s+table\b/g) {
> But can find the word directly before the last occurnace of a
> match without a loop - just with a reg expression ?

($last) = $string =~ /(\w+)\s+table(?!\w+\s+table)$/; 

-Per.
-- 
Per Kistler kistler@fnmail.com / kistler@gmx.net
------------------------------------------------------------


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

Date: Fri, 20 Aug 1999 20:46:25 -0700
From: moseley@best.com (Bill Moseley)
Subject: Re: Mail Script Question
Message-Id: <MPG.1227c0eb1b8b06be9896c8@nntp1.ba.best.com>

davidc1275@my-deja.com (davidc1275@my-deja.com) seems to say...
> I'm having a problem with a perl script. 

No you aren't.  You are having a problem with your usenet posting.  
Please seek professional help.

Check the responses you already received for the same message you posted 
on these days:

8/10/99
8/11/99
8/14/99
and now 8/20/99

Ten days and this silly problem still isn't solved?

-- 
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.


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

Date: Sat, 21 Aug 1999 00:14:42 -0600
From: "Arunas Salkauskas" <arunas@an!m.org>
Subject: Re: Maintaining User Sessions without Cookies
Message-Id: <37be43e0@news.cadvision.com>

you have to give the client something that it can use to identify itself.
Soe the client has to do something.  If you run everything with scripts, you
can get away with putting a sessionID into the QUERY_STRING of the URL, if
you don't use scripts or sever side includes, then you won't be able to keep
the string (tacked on after a ? at the end of th URL) there.  It's tricky,
inconvenient, but possible.  This would be the hard way of making a cookie.
But this is not a perl question, and has nothing to do with the language.
You might consider an HTML authoring group, or a web server group.
--
--
- Arunas Salkauskas
High Point Designs
www.highpointdesigns.com

Benjamin Franz wrote in message ...
>In article <37bdc6b1@news1.us.ibm.net>, SH <purchase9@hotmail.com> wrote:
>>Is there anyway in Perl to remember a specific users preferences even
after
>>they close their browser (without any client side involvement)?  Basically
a
>>shopping cart that saved information over a period of time.  If you could
>>give me a push in the right direction I would be very grateful.
>
>With the restriction postulated (no client side involvement),
>no - there is no way to achieve state persistence after they exit
>their browser.
>
>--
>Benjamin Franz




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

Date: 21 Aug 1999 02:53:25 GMT
From: "Nick Downey" <nead@neadwerx.com>
Subject: Re: modules not located in /usr/lib/perl5
Message-Id: <01beeb80$2f70dea0$73463d80@r52h83>

> 
> use lib '/doc_root/modules';
> 
Thank you David.


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

Date: 21 Aug 1999 05:16:48 GMT
From: justyaz@aol.com (JustYaz)
Subject: Re: Newbie : tr/// question
Message-Id: <19990821011648.26377.00002092@ng-fz1.aol.com>

Thank you all for answering my question.  I finally figured
out what the difference is between the s/// and tr///
functions.  Your help is greatly appreciated.




Peace,   Vm
Yaz


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

Date: Fri, 20 Aug 1999 22:26:54 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: newbie CGI question re CGI.pm
Message-Id: <MPG.1227d872f134ddae989e8e@nntp.hpl.hp.com>

In article <37BDF9AC.AD12AF9F@chatbase.com> on Fri, 20 Aug 1999 17:58:20 
-0700, TRG Software: Tim Greer <webmaster@chatbase.com> <TRG Software: 
Tim Greer <webmaster@chatbase.com>> says...
> either Jana or John wrote:
 ...
> #!/usr/bin/perl
> 
> > use CGI qw(:standard);
> > my $echoline = param("anecho");
> > print header, start_html("Yes, there is an echo!"), h1("You typed");
> >  if ($echoline) {
> >    print q($echoline);
> > } else {
> >    print q("You didn't type anything.");
>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> There's no reason to use q() here, unless you want it print the double
> quotes. :-)

Or even worse, to print the string C<$echoline> in the other branch.

'either Jana or John' implied that s/he meant to use the CGI 
paragraphing function p(), and that these q() were oversights.

<QUOTE>
Also -- remember I don't know this code, I just copied it from a book 
I changed the q's to p's because all the other examples in the
book have p's.  I know it's lame, but I'm dying to get something
running. -- same exact error message.  (I kept the p's, BTW)
</QUOTE>

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sat, 21 Aug 1999 10:39:35 +0800
From: benny chee <bennycc@pacific.net.sg>
Subject: packing raw IP packet
Message-Id: <37BE1166.4A1D3A4B@pacific.net.sg>

Hi,

    I m having some problem packing a raw IP UDP packet.
    Just wanna know if i set the correct pack values?

Benny
bennycc@pacific.net.sg

    Here goes:

  my $hdr = pack ('H2 H2 n n B16 C2 n a4 a4 n n n v a*',
    $versionAndHeaderLength, #H2
    $typeOfService,          #H2
    $totalLength,            #n
    $fragmentation,          #n
    $flagsAndFragmentOffset, #B16
    $TTL,                    #C
    $protocol,               #C
    $headerChecksum,         #n
    $sourceIP,               #a4
    $destIP,                 #a4
    $sourcePort,             #n
    $destPort,               #n
    $UDPLength,              #n
    $UDPChecksum,            #v
    $data);                  #a*




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

Date: Fri, 20 Aug 1999 19:26:32 +0200
From: Christoph Wernli <cw@dwc.ch>
Subject: Re: processing html on the fly part 2
Message-Id: <37BD8FC8.B66CA30C@dwc.ch>

Jeff wrote:
> 
> When I run a perl script from my cgi-bin that processes an HTML page and
> 
> then spits the page out to the browser, the web browser treats the
> cgi-bin
> as the starting directory to find images and reference all the paths in
> the
> web page. I want the web browser to look in another directory, say
> http_docs, and use that as the base path. How can I accomplish this in
> perl?
> Is their an ENV var I need to set or something?
> 
> I know you can use <base href="blah...."> in the HTML but I want to do
> this within the perl  environment. Javascript doesn't use the <base> tag
> and you have to set a javascript variable in addition to the <base> if
> you go this route.

Hey hey, wait a sec: Perl is excellent, sometimes it is capable of doing 'magic', but it
can't perform that much magic over the network as you're desiring ;)

To be more precise: You want "the browser" to treat something as "the starting directory",
but you want to accomplish it in the "perl environment". Two different things, right ? =>
go parse the HTML.

Have fun,

-w


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

Date: Sat, 21 Aug 1999 04:28:09 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: Recursing through directory headache
Message-Id: <tVpv3.2624$J72.536432@news.itd.umich.edu>

In article <7pkohp$ce1$1@charm.magnus.acs.ohio-state.edu>,
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
>[A complimentary Cc of this posting was sent to Sean McAfee
><mcafee@waits.facilities.med.umich.edu>],
>who wrote in article <TBkv3.2598$J72.533169@news.itd.umich.edu>:
>> Second, I hate to break it to you, but the hard work has already been done.
>> Use the standard File::Find module.

>I hate to break it to you, but please explain how File::Find can work
>in presence of renames.

How?  Well, the module's code can be found in $dir/File/Find.pm, where
$dir is one of the elements of Perl's @INC array.  A full discussion of the
logic is beyond the scope of this article.  In short, there's no reason why
not.

-- 
Sean McAfee                                                mcafee@umich.edu
print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!


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

Date: 21 Aug 1999 04:38:56 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Recursing through directory headache
Message-Id: <7plah0$euu$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was sent to Sean McAfee
<mcafee@waits.facilities.med.umich.edu>],
who wrote in article <tVpv3.2624$J72.536432@news.itd.umich.edu>:
> >> Second, I hate to break it to you, but the hard work has already been done.
> >> Use the standard File::Find module.
> 
> >I hate to break it to you, but please explain how File::Find can work
> >in presence of renames.
> 
> How?  Well, the module's code can be found in $dir/File/Find.pm, where
> $dir is one of the elements of Perl's @INC array.  A full discussion of the
> logic is beyond the scope of this article.  In short, there's no reason why
> not.

Well, it is me who wrote a significant part of the code you discuss.
And there is a lot of reason why not.

Ilya


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

Date: Sat, 21 Aug 1999 05:09:37 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: Recursing through directory headache
Message-Id: <lwqv3.2627$J72.536834@news.itd.umich.edu>

In article <7plah0$euu$1@charm.magnus.acs.ohio-state.edu>,
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
>[A complimentary Cc of this posting was sent to Sean McAfee
><mcafee@waits.facilities.med.umich.edu>],
>who wrote in article <tVpv3.2624$J72.536432@news.itd.umich.edu>:
>> >I hate to break it to you, but please explain how File::Find can work
>> >in presence of renames.

>> How?  Well, the module's code can be found in $dir/File/Find.pm, where
>> $dir is one of the elements of Perl's @INC array.  A full discussion of the
>> logic is beyond the scope of this article.  In short, there's no reason why
>> not.

>Well, it is me who wrote a significant part of the code you discuss.
>And there is a lot of reason why not.

Okay, I give up.  Why not?

I tested the code I posted, and it appeared to work as advertised.

-- 
Sean McAfee | GS d->-- s+++: a27 C++ US+++$ P+++ L++ E- W+ N++ |
            | K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
            | tv+ b++ DI++ D+ G e++>++++ h- r y+>++**          | umich.edu


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

Date: 21 Aug 1999 06:47:42 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Recursing through directory headache
Message-Id: <7pli2e$gue$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was sent to Sean McAfee
<mcafee@waits.facilities.med.umich.edu>],
who wrote in article <lwqv3.2627$J72.536834@news.itd.umich.edu>:
> >Well, it is me who wrote a significant part of the code you discuss.
> >And there is a lot of reason why not.
> 
> Okay, I give up.  Why not?
> 
> I tested the code I posted, and it appeared to work as advertised.

Effectively, you are iterating through a hash, while changing the
hash.  See

  perldoc -f each

on hints.

Note that on primitive file systems, such as DOS's FAT or
kitchentop-Unixen's ones, an inside-the-directory file rename can happen
without changing the layout of the directory "record", so you will not
see any side effects.  But, say, OS/2's HPFS keeps an ordered B-tree
for each directory, thus renames there should cause a tree modification.

[Note that I got this idea only after reading your initial reply.  I
 was using my pfind script (based on File::Find) for years (mostly on
 HPFS) without any glitch.  Probably the renames I was doing were very
 "local" (say, a change of an extension), and were not changing the
 ordering.]


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

Date: Fri, 20 Aug 1999 23:39:14 -0400
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Regular Expression woes
Message-Id: <37BE1F62.50CE7735@rochester.rr.com>

Bill Moseley wrote:

> Maybe two hours of the dentist drilling on me did some damage.  Can
> someone help me understand what's going on here?
>
> I'm using the META tags below to pass parameters from a text file into
> the program AND to then remove the tags before printing the text.
>
> The example below contains two while() statements.  Both work to capture
> the data, yet only the first will then go on to delete the tag from $x.
>
> #! perl -w
> use strict;
>
> my $x = <<'EOF';
> Plain text here
> <META NAME="highlight_start" CONTENT="\<em\>">
> <META NAME="highlight_end" CONTENT="\</em\>">
> remove me
> more plain text
> removed you
> <TITLE>Title Text here</TITLE>
> EOF
>
> print "$x\n";
>
> my %hash;
>
> #while ($x =~ /(remove.*) (\w+)/g ) {
> while ( $x =~ /<META\s+NAME="(.+?)"\s*CONTENT="(.+?)">/g ) {
>
>     $hash{ $1 } = $2;
>
>     print $x =~ s/$&//

Bill, on the line above, the $& has as contents the first time through:

<META NAME="highlight_start" CONTENT="\<em\>">

When this is interpreted as a regular expression, the backslashes are
regular expression metacharacters, which don't match literally, but rather
escape or give special meaning to the character following.  You need to
quote regular expression metacharacters in your string.  One way is:

print $x =~ s/\Q$&\E//

Your other while loop matched a string that didn't contain any regular
expression metacharacters, so it (luckily) didn't have that problem.

>
>           ? "Removed: '$&'\n"
>           : "Failed to Remove: '$&'\n"

Recognize that here $& is the new $& that matched in the print statement (if
there was a match).  In this case it is the same value, match or no match,
so you are OK.

>
> }
>
> print "\n$x\n";
>
> print "$_ => $hash{$_}\n" for keys %hash;
>
> --
> Bill Moseley mailto:moseley@best.com
> pls note the one line sig, not counting this one.

Bob Walton



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

Date: Fri, 20 Aug 1999 20:59:17 -0700
From: moseley@best.com (Bill Moseley)
Subject: Re: Regular Expression woes
Message-Id: <MPG.1227c3ebf0bcbdbd9896c9@nntp1.ba.best.com>

Bob Walton (bwalton@rochester.rr.com) is much appreciated in his post 
of...
> >     print $x =~ s/$&//
> <META NAME="highlight_start" CONTENT="\<em\>">
> 
> When this is interpreted as a regular expression, the backslashes are
> regular expression metacharacters, which don't match literally, but rather
> escape or give special meaning to the character following. 

Oh, that helps a lot.  Thanks very much.

Too bad I can't write:

while ( $x =~ s/<META\s+NAME="(.+?)"\s*CONTENT="(.+?)">//g ) {
    $hash{ $1 } = $2;
}

> >           ? "Removed: '$&'\n"
> >           : "Failed to Remove: '$&'\n"
> 
> Recognize that here $& is the new $& that matched in the print statement (if
> there was a match). 

Right, that was the intention.  I wanted to see if the pattern I just 
matched in the while was matching again.

I owe you a beer.

-- 
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.


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

Date: Sat, 21 Aug 1999 02:04:35 +0200
From: Per Kistler <kistler@fnmail.com>
Subject: Re: Regular Expression woes
Message-Id: <37BDED13.C0DE7021@fnmail.com>

Bill Moseley wrote:
> while ( $x =~ /<META\s+NAME="(.+?)"\s*CONTENT="(.+?)">/g ) {

$all{$i++} = $&; #save it

>     $hash{ $1 } = $2;
>     print $x =~ s/$&//
>           ? "Removed: '$&'\n"
>           : "Failed to Remove: '$&'\n"
> }

#only afterward change $x "\Q" in case there are regexp chars
map { $x =~ s/\Q$_//; } values %all;

Just an idea (, not tested).
-Per.
-- 
Per Kistler kistler@fnmail.com / kistler@gmx.net
------------------------------------------------------------


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

Date: 21 Aug 1999 02:54:38 GMT
From: tgy@chocobo.org (Neko)
Subject: Re: Shell vs Perl
Message-Id: <7pl4de$82q$0@216.39.141.200>

On Fri, 20 Aug 1999 18:10:10 -0700, lr@hpl.hp.com (Larry Rosler) wrote:

>In article <7pks0m$ijt$0@216.39.141.200> on 21 Aug 1999 00:31:18 GMT, 
>Neko <tgy@chocobo.org> says...
>...
>> Not that the system administrator is necessarily a beginner in Perl, but
>> compared to his ksh script, he may still find that too complicated.  If so,
>> then perhaps the following will meet his criterion for simplicity.
>> 
>> #!/usr/bin/perl
>> 
>> print @ARGV
>>     ? `grep "[:/]$ARGV[0]\[:/]" /etc/passwd | sort -t: +2n -3`
>>     : `sort -t: +2n -3 /etc/passwd`;
>
>Sure.  Why not let the commands do the printing?

An unfounded fear that the commands have a different STDOUT.  A preference
for backticks.  A lower Perl golf score.  Choose whichever makes me look less
stupid. :)

>  #!/usr/bin/perl
>  
>  system(@ARGV ? qq{grep "[:/]$ARGV[0]\[:/]" /etc/passwd |
>          sort -t: +2n -3} :
>      : 'sort -t: +2n -3 /etc/passwd');
>
>You may be trying to be funny, but I look in vain for a smiley.  Your 
>program may be written using Perl syntax, but it is a shell program 
>nonetheless.

There is no lack of seriousness in the response I gave.  The want was for
simplicity.  Calling the shell is a perfectly valid incantation.  Call it
cheating or call it a shell program if you want, but the next thing you know,
the ksh advocate will include a call to 'sendmail' and 'man' and 'patch' in
his script and challenge you to do the same in Perl and without a lost in
simplicity.

[snip difference between shell and Perl program]

>Your program consists of command invocations, so it is a shell program 
>in Perl clothing.  It proves nothing about the capabilities of Perl.  
>Sean's program does.

Punting to the shell is actually a pretty nifty capability.  It's nice to be
able to glue things together in Perl.  And the game was not too prove what
Perl could do with on hand behind its back and blindfolded.  It was about
simplicity.

I in no way implied that my program was in any way better than Sean's, only
that it was simpler.

-- 
Neko | tgy@chocobo.org | Will hack Perl for a moogle stuffy! =^.^=


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

Date: 20 Aug 1999 23:22:18 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Shell vs Perl
Message-Id: <m1hfltd55x.fsf@halfdome.holdit.com>

>>>>> "kcounts" == kcounts  <kcounts@my-deja.com> writes:

kcounts> Well,
kcounts> I have a question to so humbly ask of all Perl compatriots.

kcounts> The system administrator at my workplace doesn't believe
kcounts> that a  Perl program  can be written to mimic the functionality of the
kcounts> below shell script and still keep as simple as the shell script.


kcounts> !#/usr/bin/ksh

kcounts> if [ "$1" = "" ]
kcounts>     then sort -t: +2n -3 /etc/passwd
kcounts> else
kcounts>     grep "[:/]$1[:/]" /etc/passwd | sort -t: +2n -3
kcounts> fi

Well, here's the equivalent Perl program:

    #!/usr/bin/perl
    exec '/bin/ksh', '-c', <<'StuffyFunk', $0, @ARGV;
    if [ "$1" = "" ]
	then sort -t: +2n -3 /etc/passwd
    else
	grep "[:/]$1[:/]" /etc/passwd | sort -t: +2n -3
    fi
    StuffyFunk

As generated by my "sh2perl" program, in the CPAN.

:-)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 21 Aug 1999 02:32:50 GMT
From: njpin@aol.com (NJPin)
Subject: Syntax of format
Message-Id: <19990820223250.24750.00001331@ng-cj1.aol.com>

Hi guys -

I've been struggling over this one for hours:  none of the Perl books/man pages
are shedding any light on it for me and I'm hoping someone here can help.  I'm
sure it's a really stupid error and I'm going to be kicking myself for it, but
I just can't find it!  I get these errors:

Write on closed filehandle at dbmain.pl line 75, <STDIN> chunk 1.
        main::addc() called at dbmain.pl line 40
        main::prog_menu called at dbmain.pl line 14
Write on closed filehandle at dbmain.pl line 80, <CATEGORIES> chunk 1.
        main::addc() called at dbmain.pl line 40
        main::prog_menu called at dbmain.pl line 14
Write on closed filehandle at dbmain.pl line 80, <CATEGORIES> chunk 2.
        main::addc() called at dbmain.pl line 40
        main::prog_menu called at dbmain.pl line 14
Write on closed filehandle at dbmain.pl line 80, <CATEGORIES> chunk 3.
        main::addc() called at dbmain.pl line 40
        main::prog_menu called at dbmain.pl line 14
Write on closed filehandle at dbmain.pl line 80, <CATEGORIES> chunk 4.
        main::addc() called at dbmain.pl line 40
        main::prog_menu called at dbmain.pl line 14

when trying to use these format statements:

format CURR_CAT_TOP =
Current Categories

Name                              Abbreviation
----------------------------------------------
 .

format CURR_CAT_LIST = 
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<   ^<<<<<<<<<<<
$name,                            $abbrev
 .

with this loop:

	open(CATEGORIES,"./db/cat.all") || die "Can not open categories file
(./db/cat.all):  $!";
	write (CURR_CAT_TOP);
	
	while(<CATEGORIES>) {
		chomp;
		($name,$abbrev)=split(/:/);
		write (CURR_CAT_LIST);
	}

	print "\n";
	close(CATEGORIES);


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

Date: 21 Aug 1999 03:02:08 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Syntax of format
Message-Id: <slrn7rs5mj.517.sholden@pgrad.cs.usyd.edu.au>

On 21 Aug 1999 02:32:50 GMT, NJPin <njpin@aol.com> wrote:
>Hi guys -
>
>I've been struggling over this one for hours:  none of the Perl books/man pages
>are shedding any light on it for me and I'm hoping someone here can help.  I'm
>sure it's a really stupid error and I'm going to be kicking myself for it, but
>I just can't find it!  I get these errors:
>
>Write on closed filehandle at dbmain.pl line 75, <STDIN> chunk 1.
<snip lots of the same>
>
>with this loop:
<snip code>
>	write (CURR_CAT_TOP);
<snip more code>

I would guess that CURR_CAT_TOP has been closed at some stage.

If you need help with perl diagnostic messages then you should read the 
documentation on them that comes with perl.

perldoc perldiag

-- 
Sam

I would like to tell you that Perl is simple in its complexity. But some
people won't understand that. So pretend I didn't say that, unless you
do.   --Larry Wall


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

Date: Sat, 21 Aug 1999 14:22:32 +1000
From: elephant@squirrelgroup.com (elephant)
Subject: Re: The real reason people don't use CGI.pm
Message-Id: <MPG.1228d491b0045829989c6d@news-server>

Alan Curry writes ..
>[2] By the way, are HTTP cookies described in any RFC? I don't like reading
>"specifications" from netscape.com.

I really don't know - but Netscape suggest that from Navigator 3.0 on - 
they are in compliance with RFC2109 "HTTP State Management Mecahnism" 
(which a Netscape employee wrote - so I don't know how much better that 
is than reading the doc straight from netscape.com)

I have no idea what cookie standard the other browsers support .. but 
it'd either be the above RFC or Netscape's original proposal

  http://home.netscape.com/newsref/std/cookie_spec.html

-- 
 jason - elephant@squirrelgroup.com -


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

Date: Sat, 21 Aug 1999 10:22:11 +0530
From: "Sreshth Kumar" <skumar@deutech.com>
Subject: Time as per IST??
Message-Id: <7pmfsb$c3u$2@news.vsnl.net.in>

Suppose I want to display all times according to IST (GMT + 5:30) the
easiest way to do it would be to add 5 hours and 30 minutes to the time
returned by gmtime(). How do I do this?

Or for that matter how does one increment / decrement time by a given number
of hours/minutes/seconds?

Thanks in advance for your help.

Sreshth K

* Deucalion Technologies
* http://www.deutech.com





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

Date: Sat, 21 Aug 1999 02:25:49 GMT
From: Wael Hassan <wael@ieee.org>
Subject: Using System Or Exec from a perl script
Message-Id: <37BE0DB8.14E98E35@ieee.org>

Hi,
I was trying to run an Executable file from the Perl script.
If I run the program from the shell, it works perfectly.
Yet when I call the perl script, it reports success, yet the
program does not what it is meant to do.


Thanks

--
Wael

Are you looking for privacy??
Go to  http://www.zeroknowledge.com/clickthrough/click.asp?partner_id=1641




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

Date: Fri, 20 Aug 1999 23:11:57 -0400
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Using System Or Exec from a perl script
Message-Id: <37BE18FC.A6C4F418@rochester.rr.com>

Wael Hassan wrote:

> Hi,
> I was trying to run an Executable file from the Perl script.
> If I run the program from the shell, it works perfectly.
> Yet when I call the perl script, it reports success, yet the
> program does not what it is meant to do.

Works fine for me.  You'll have to provide additional detail:  what is your
OS, what version of Perl, what shell are you using, the exact Perl code and
error messages that give you trouble (a very short example using common
commands everyone using your OS would have on their system is best) -- without
that info, no one can help you.

>
>
> Thanks
>
> --
> Wael
>
> Are you looking for privacy??
> Go to  http://www.zeroknowledge.com/clickthrough/click.asp?partner_id=1641



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

Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 99)
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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. Due to their sizes, neither the Meta-FAQ nor
the FAQ are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq" from
almanac@ruby.oce.orst.edu. 

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 V9 Issue 608
*************************************


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