[18759] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 927 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 18 00:05:41 2001

Date: Thu, 17 May 2001 21:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <990158709-v10-i927@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 17 May 2001     Volume: 10 Number: 927

Today's topics:
        "Re: Match Parsing Glitch <nospam@xx.com>
    Re: -c: misses close FOO, or die "whatever" (cabney)
    Re: An Example Of A Polite FAQ (Tad McClellan)
    Re: An Example Of A Polite FAQ <centreman_19@NOSPAMyahoo.com>
        Calling an undefined variable <pswordkirk@msn.com>
    Re: Can you build GUI's with perl? <jck1@mail2000.com.tw>
        cookie implementation <troyr@vicnet.net.au>
    Re: cookie implementation <rebelvideo@hotmail.com>
    Re: cookie implementation (Craig Berry)
    Re: cookie implementation <troyr@vicnet.net.au>
    Re: cookie implementation (Craig Berry)
    Re: Curious Newbie asks a question <centreman_19@NOSPAMyahoo.com>
        HTTP Login <blah@blah.com>
        Match Parsing Glitch <nospam@xx.com>
    Re: Match Parsing Glitch (Jay Tilton)
    Re: Match Parsing Glitch <nospam@xx.com>
    Re: Match Parsing Glitch <krahnj@acm.org>
    Re: Match Parsing Glitch (Jay Tilton)
    Re: Match Parsing Glitch <nospam@xx.com>
    Re: Match Parsing Glitch (Tad McClellan)
    Re: Match Parsing Glitch (Jay Tilton)
    Re: Match Parsing Glitch <nospam@xx.com>
    Re: Match Parsing Glitch <krahnj@acm.org>
    Re: Match Parsing Glitch <nospam@xx.com>
        Need Example creating Registry variable names <vGeesink@Planet.NL>
    Re: POP3Client (Joe Smith)
    Re: Random Numbers Script <godzilla@stomp.stomp.tokyo>
    Re: Sending wav-file through perl-script <rebelvideo@hotmail.com>
    Re: Sending wav-file through perl-script <godzilla@stomp.stomp.tokyo>
    Re: Sending wav-file through perl-script <flavell@mail.cern.ch>
    Re: Writing to Unix passwd <djm@spamfree.mcoe.k12.ca.us>
    Re: Writing to Unix passwd (Tad McClellan)
    Re: Writing to Unix passwd (Alan Barclay)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 17 May 2001 20:24:55 -0700
From: Eric <nospam@xx.com>
Subject: "Re: Match Parsing Glitch
Message-Id: <3B049607.4F3C6706@xx.com>

Jay Tilton wrote:

> And if that doesn't work, I'd suggest trying substr() before going
> back to the regex approach.
> 
OK...I tried this (code snippet below), but am still getting that #&^!
"Uninitialized chuncks..." error message and don't understand it.

 if ($line =~ m/.*\d{6}/)
  
  {
   substr($line, 12, 7) = $vendor;
   substr($line, 29, 10) = $price;
   substr($line, 50, 25) = $addr;
       $price =~ tr/$,//d;                            #remove $ and
comma on price  
       $addr =~ s/^\s+|\s+$//g;                 #whitespace cleanup on
address                                                                
       &writestatsfile unless $line !~ m/.*\d{6}/;    #only call
subroutine if valid line to parse
  }

The subroutine writes to a file, but every entry is:  ,,""  and that's
it.  Bizarre ;-(

Eric


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

Date: Fri, 18 May 2001 00:12:34 GMT
From: cabney@vespidae.occultbias.net (cabney)
Subject: Re: -c: misses close FOO, or die "whatever"
Message-Id: <slrn9g8q7o.p9t.cabney@vespidae.occultbias.net>

Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>According to cabney <cabneySPAM@SPAM.SPAMcyberpass.net>:

>> 	close V, or die ("er, huh?: $!\n");
>> 
>> is valid syntax for perl -c... I even used both -w and 'use strict'.

[stuff about trailing comma operators in scalar/list context, snipped]

>The documented behavior is to ignore the extra comma.

Thanks for helping me figure out how perl parsed that. In a list
context I wouldn't have had a problem with it (I've read a little of
the documentation), but this one surprised me a bit.

Perl is almost inhuman in its ability to do the right thing. :)

CA
-- 
There was a time
A wind that blew so young
For this could be the biggest sky
And I could have the faintest idea


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

Date: Thu, 17 May 2001 18:46:07 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: An Example Of A Polite FAQ
Message-Id: <slrn9g8l5f.r2q.tadmc@tadmc26.august.net>

Dave VP <me@my_no_spam.org> wrote:

>As I've read through the various threads on FAQs and guidelines posted
>in clpm the past few days, I've come to realize that:


I think your points are already known by most who have been
regular readers for a year or two.

In other words, yeah, I think you're right.


>	1.  There are folks who just *won't* RTFM
>	2.  There are folks who have never programmed in *any* language.
>	3.  There are extremely knowledgeable and helpful people in this group.
>	4.  There are those who would *like* to learn, 
>	    but are having trouble getting up the slope.
>
>There's nothing to be done about nos. 1 & 2.  


Hold on hoss!

Nothing wrong with being a number 2. You are not required
to have programmed in another language to post here, while you
are required to CTFM (check, not read).

#1 and #2 should in no way be lumped together.

#1s get -9998 in my scorefile, #2s may get positive scores. Nearly
opposite ends of the spectrum.


I also differ on the "nothing to be done" part with regards
to #1s. 


>They're everywhere!


I have noticed that there are "clusters" of them at certain domains.

I am doing something (i.e. not "nothing") with that information.

I expect others are too.


>I believe that targeting the guidelines to this last group would be of
>the greatest benefit.


I have assumed this all along. Have I missed the target?


>I *hope* that it would cut down some of the wasted bandwidth.

<snort>

Usenet is lost. We will be assimilated.


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


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

Date: Thu, 17 May 2001 17:25:06 -0700
From: "Brandon Thornburg" <centreman_19@NOSPAMyahoo.com>
Subject: Re: An Example Of A Polite FAQ
Message-Id: <9e1qfr$5bv$1@fremont.ohsu.edu>

<snip>
This example is sorely lacking. A person may not know a requirement is to
change to a directory within or under your Perl install directory.
My example also lacks qualification of a command line prompt; is it a unix
prompt, a dos prompt or other?
<end snip>

My first reaction to this statement was, "Oh my lord, who doesn't know to
change directories and yet wants to write in Perl?" Then I realized that
same impulse is the place that the rude responses _I_ rail against. All I'm
saying is, if I can be guilty of that impulse, we all can, but to me that
means we should all be even that much more on our guard against it.




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

Date: Fri, 18 May 2001 03:53:37 GMT
From: "KapTin KiRk" <pswordkirk@msn.com>
Subject: Calling an undefined variable
Message-Id: <511N6.8203$v5.718202@news1.rdc1.ct.home.com>

I'm using modules and about 5 files that access that module. The module
connects to a DBM database, reads it, and prints out the results. However,
each of those 5 files will be looking for something different in the
database. I've tried this...

#in the 5 files#
$searchfor = $Genre;


#in the module#
 while (($key, $value) = each %dbmdata) {
  ($Title, $PreviewURL, $ReviewURL, $Rating, $Release, $Genre) =
split(/$DELIM/, $value);
 if ($searchfor =~ /$ID/) {
print some stuff
} }

 ... but as you can see, the value of $Genre doesn't get defined until the
database is open. How on earth would I go about getting this to work as
intended?

- KapTin KiRk




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

Date: Fri, 18 May 2001 09:32:22 +0800
From: "jackkon" <jck1@mail2000.com.tw>
Subject: Re: Can you build GUI's with perl?
Message-Id: <9e1ud9$fg8@netnews.hinet.net>


Dan Baker <dan@nospam_dtbakerprojects.com> wrote in message > Managing state
information is a challange, but with cookies, temp text
> files, or database interfaces it is certainly possible. I have found
> prototyping an interface with standard html tools to be faster than
> learning TK....
> D


HI..........
I am new in Tk.
Could you show me some examples about prototyping an interface with standard
html tools?
I am very interested.
Thanks a lot.






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

Date: Fri, 18 May 2001 09:36:05 +1000
From: "Troy Boy" <troyr@vicnet.net.au>
Subject: cookie implementation
Message-Id: <9jZM6.52$Ld4.1934@ozemail.com.au>

Does anyone have a perl cookie implementation on the web?

I want to see if it saves the cookie on my browser..as a particular browser
of mine will not save perl cookies!

Thanks in advance
--
----------------------------------------------------------------
Troy Rasiah
Melbourne, Aus




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

Date: Fri, 18 May 2001 09:38:17 +0930
From: Chris <rebelvideo@hotmail.com>
To: troyr@vicnet.net.au
Subject: Re: cookie implementation
Message-Id: <3B0467F1.E6EE45A0@hotmail.com>

Hi Troy

I am interested in this as I get some browsers that refuse to save
cookies I send

If you don't mind logging in to an adult site go here to see what
happens

http://www.rebel.com.au/cgi-bin/userreg.pl

if an error occurs it will tell you

Troy Boy wrote:
> 
> Does anyone have a perl cookie implementation on the web?
> 
> I want to see if it saves the cookie on my browser..as a particular browser
> of mine will not save perl cookies!
> 
> Thanks in advance
> --
> ----------------------------------------------------------------
> Troy Rasiah
> Melbourne, Aus

-- 
Regards

Chris
rebelvideo@hotmail.com


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

Date: Fri, 18 May 2001 00:21:51 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: cookie implementation
Message-Id: <tg8qov9kebr71d@corp.supernews.com>

Troy Boy (troyr@vicnet.net.au) wrote:
: Does anyone have a perl cookie implementation on the web?

CGI.pm includes good cookie-handling tools.

: I want to see if it saves the cookie on my browser..as a particular
: browser of mine will not save perl cookies!

That's impossible as stated.  There's no way for an agent to distinguish a
perl cookie from a java cookie, or a FORTRAN cookie, or a cookie
hand-typed by a human well versed in http who is emulating a server.
Cookies carry no indication of how they were created.  If some are not
being accepted by a particular agent, then these cookies are improperly
constructed for consumption by that agent.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

Date: Fri, 18 May 2001 10:33:10 +1000
From: "Troy Boy" <troyr@vicnet.net.au>
Subject: Re: cookie implementation
Message-Id: <H8_M6.82$Ld4.2097@ozemail.com.au>

> : Does anyone have a perl cookie implementation on the web?
>
> CGI.pm includes good cookie-handling tools.
>
> : I want to see if it saves the cookie on my browser..as a particular
> : browser of mine will not save perl cookies!
>
> That's impossible as stated.  There's no way for an agent to distinguish a
> perl cookie from a java cookie, or a FORTRAN cookie, or a cookie
> hand-typed by a human well versed in http who is emulating a server.
> Cookies carry no indication of how they were created.


> If some are not
> being accepted by a particular agent, then these cookies are improperly
> constructed for consumption by that agent.

hi Craig,
            Can you explain what you mean by this last sentence. I'm using
CGI.pm

This is pretty standard..yes?
##### snip of code ####
use CGI qw(:standard);
$bookie = cookie(-name=>'sid');


    $the_cookie = cookie(-name=>'sid',
                         -value=>$session_id,
                         -expires=>'+1m',
                         -domain=>'.vicnet.net.au',
                         -path=>'/');

    print header(-cookie=>$the_cookie);






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

Date: Fri, 18 May 2001 01:57:16 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: cookie implementation
Message-Id: <tg90bsm3eeud29@corp.supernews.com>

Troy Boy (troyr@vicnet.net.au) wrote:
: > If some [cookies] are not
: > being accepted by a particular agent, then these cookies are improperly
: > constructed for consumption by that agent.
: 
: Can you explain what you mean by this last sentence. I'm using
: CGI.pm

I'm not sure what needs explaining.  If a cookie is badly formatted with
respect to a particular agent's needs, that can be determined by examining
the cookie, without reference to the language used to write the tool that
generated it.  Once you figure out what's wrong, you can then examine the
tool (or the language) to work out where the problem is.

:                          -expires=>'+1m',

You do know that's one minute, not one month, right?  It's quite possible
that you're simply not getting back to the site before the cookie expires.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

Date: Thu, 17 May 2001 17:16:09 -0700
From: "Brandon Thornburg" <centreman_19@NOSPAMyahoo.com>
Subject: Re: Curious Newbie asks a question
Message-Id: <9e1pv2$56l$1@fremont.ohsu.edu>

Correct me if I'm wrong, but I think what you're looking for can be achieved
by setting a cookie on the user's system...then have each of the areas on
your website check for that cookie to get the registration information.

As far as keeping the registration information, I'm less sure about how to
do that in perl...but the CGI::Cookie module should help you at least to get
started.






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

Date: Thu, 17 May 2001 11:10:54 -0400
From: "Mike Mesarch" <blah@blah.com>
Subject: HTTP Login
Message-Id: <9e23rv$hs$1@sshuraac-i-1.production.compuserve.com>

I would like to download some files from an web site, but the site requires
me to pass my username and password.  How can I have perl pass this
information when prompted?

Thanks!
-Mike




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

Date: Thu, 17 May 2001 17:01:39 -0700
From: Eric <nospam@xx.com>
Subject: Match Parsing Glitch
Message-Id: <3B046663.DB985D9C@xx.com>

I'm trying to retweak a script to parse 3 pieces of data from a single
line of data but am obviously missing something.  HELP!!!

The data file line format is:

DATA FILE FORMAT LINES TO PARSE (complete file contains blank lines &
other stuff)
003 046926 MXF  08 1/1/5    $2,400,000  22/NO/00 4285 AN ADDRESS
HERE       C5D5
005 948573 AQPT392 1/1/5    $1,755,500  13/SE/99 44283 SOME NAME
HERE       C5D5
007 453981 RVQA 02 1/1/5    $835,000    19/OC/99 314 WHATEVER
HERE          C5D5
etc., etc.

I need to get 3 components to write to an ASCII .csv file:

1. SEVEN characters (including any white spaces) in the column
containing MXF  08, AQPT392, RVQA 02) ... Vendor Codes
2. TEN characters in the price column (column is left-justified, but
MUST strip out the $, any commas, and any trailing white spaces
3. 25 characters in the left-justifed address column following the date
format (this has worked AOK before)

The applicable portion of script code I'm got so far & trying to get
straightened out is:

$line =~
m/\d{3}\s\d{6}\W(\W{7})\s{4}(\W{10})\s{2}\d{2}\/\D{2}\/\d{2}\s(.{5,25})/; 
								#extract Vendor Code, Price
								#and Address from this data line
       $vendor = $1;                            #assign vendor code from
$1
       $price = $2;                             #assign price from $2
 #      NOTE: HOW TO REMOVE THE $ *AND* THE COMMAS FROM THE PRICE?????

       $addr = $3;                              #assign address from $3
       $addr =~ s/^\s+|\s+$//g;                 #whitespace cleanup on
address

Thanks in advance for helping me see what I've missed here.

Eric (Please Post only ... no e-mail)


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

Date: Fri, 18 May 2001 00:49:38 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Match Parsing Glitch
Message-Id: <3b046754.401453189@news.erols.com>

On Thu, 17 May 2001 17:01:39 -0700, Eric <nospam@xx.com> wrote:

[huge snip]

>$line =~
>m/\d{3}\s\d{6}\W(\W{7})\s{4}(\W{10})\s{2}\d{2}\/\D{2}\/\d{2}\s(.{5,25})/; 

Holy smokes.

IMHO 'unpack' is a better tool for bursting a record into fixed-width
fields than a regex.  It's easier to fix when things go screwy or, as
is especially evident here, don't work at all.

  my (undef, $vendor, undef, $price, undef, $addr) =
     unpack 'A11 A7 A10 A10 A11 A25', $_;

> #      NOTE: HOW TO REMOVE THE $ *AND* THE COMMAS FROM THE PRICE?????

  $price =~ s/[,\$]//g;



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

Date: Thu, 17 May 2001 18:17:48 -0700
From: Eric <nospam@xx.com>
Subject: Re: Match Parsing Glitch
Message-Id: <3B04783C.5141DD63@xx.com>

Thanks, Jay, but tried this and get the following error:

   Can't declare undef operator in my at [filename.pl] ........

Do I have to make some further assignments or somthing???  Looked up
'unpack' in my Programming Perl book but am lost here.

Eric

Jay Tilton wrote:
> 
> On Thu, 17 May 2001 17:01:39 -0700, Eric <nospam@xx.com> wrote:
> 
> [huge snip]
> 
> >$line =~
> >m/\d{3}\s\d{6}\W(\W{7})\s{4}(\W{10})\s{2}\d{2}\/\D{2}\/\d{2}\s(.{5,25})/;
> 
> Holy smokes.
> 
> IMHO 'unpack' is a better tool for bursting a record into fixed-width
> fields than a regex.  It's easier to fix when things go screwy or, as
> is especially evident here, don't work at all.
> 
>   my (undef, $vendor, undef, $price, undef, $addr) =
>      unpack 'A11 A7 A10 A10 A11 A25', $_;
> 
> > #      NOTE: HOW TO REMOVE THE $ *AND* THE COMMAS FROM THE PRICE?????
> 
>   $price =~ s/[,\$]//g;


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

Date: Fri, 18 May 2001 02:30:48 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Match Parsing Glitch
Message-Id: <3B04896A.BA8867C5@acm.org>

Eric wrote:
> 
> I'm trying to retweak a script to parse 3 pieces of data from a single
> line of data but am obviously missing something.  HELP!!!
> 
> The data file line format is:
> 
> DATA FILE FORMAT LINES TO PARSE (complete file contains blank lines &
> other stuff)
> 003 046926 MXF  08 1/1/5    $2,400,000  22/NO/00 4285 AN ADDRESS
> HERE       C5D5
> 005 948573 AQPT392 1/1/5    $1,755,500  13/SE/99 44283 SOME NAME
> HERE       C5D5
> 007 453981 RVQA 02 1/1/5    $835,000    19/OC/99 314 WHATEVER
> HERE          C5D5
> etc., etc.
> 
> I need to get 3 components to write to an ASCII .csv file:
> 
> 1. SEVEN characters (including any white spaces) in the column
> containing MXF  08, AQPT392, RVQA 02) ... Vendor Codes
> 2. TEN characters in the price column (column is left-justified, but
> MUST strip out the $, any commas, and any trailing white spaces
> 3. 25 characters in the left-justifed address column following the date
> format (this has worked AOK before)
> 
> [code snipped]

my ( $vendor, $price, $addr ) = unpack 'x11 A7 x10 A10 x11 A25', $line;
$price =~ tr/$,//d;

Or if the dollar sign is allways in the same column:

my ( $vendor, $price, $addr ) = unpack 'x11 A7 x11 A9 x11 A25', $line;
$price =~ tr/,//d;



John
-- 
use Perl;
program
fulfillment


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

Date: Fri, 18 May 2001 02:42:24 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Match Parsing Glitch
Message-Id: <3b04830f.408552964@news.erols.com>

[In future, post your reply after the quoted material]

On Thu, 17 May 2001 18:17:48 -0700, Eric <nospam@xx.com> wrote:
>Jay Tilton wrote:
>>   my (undef, $vendor, undef, $price, undef, $addr) =
>>      unpack 'A11 A7 A10 A10 A11 A25', $_;
>>   $price =~ s/[,\$]//g;
>
>Thanks, Jay, but tried this and get the following error:
>
>   Can't declare undef operator in my at [filename.pl] ........

I see.  I'm not familiar with that error,
except as a specific case of "Can't declare [x] in [y]".
It doesn't happen with my perl (ActiveState 5.6.0).
If a guru reading this knows what's going on, speak up.

In the meantime, it can be worked around.
Instead of using 'undef' on the LHS to discard returned values, make
the unpack template do the discarding.

  my ($vendor, $price, $addr) =
    unpack 'x11 A7 x10 A10 x11 A25', $line;
  # Instead of $_ in the last example^^^^^  Sorry about that.

And if that doesn't work, I'd suggest trying substr() before going
back to the regex approach.

>Do I have to make some further assignments or somthing???  Looked up
>'unpack' in my Programming Perl book but am lost here.

Much like regexes, it can be confusing at first, but it's very useful
once you wrap your brain around it.  Working from the other end by
studying 'pack' might help.


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

Date: Thu, 17 May 2001 20:07:02 -0700
From: Eric <nospam@xx.com>
Subject: Re: Match Parsing Glitch
Message-Id: <3B0491D6.A40B10BF@xx.com>

"John W. Krahn" wrote:

Hi John:

Thanks for the info...close to what Jay posted, however I still can not
get this darn thing working.  I keep getting "Uninitialized chunks..."
error messages and am clueless about what's wrong.  What am I missing???

Here's the complete script with data format (some of the beginning data
file lines have non-formatted text in the actual files):

Tnx.

Eric


#!/usr/bin/perl -w
# stats.pl
# 
# DATA FILE FORMAT LINES TO PARSE (complete file contains blank lines &
other stuff)
# 003 046926 MXF  08 1/1/5    $2,400,000  22/NO/00 4285 AN ADDRESS
HERE       C5D5
# 005 948573 AQPT392 1/1/5    $1,755,500  13/SE/99 44283 SOME NAME
HERE       C5D5
# 007 453981 RVQA 02 1/1/5    $835,000    19/OC/99 314 WHATEVER
HERE          C5D5
#
# Address is 25 or less characters after the single space following the
dd/mm/yy date
#
# START OF PERL SCRIPT
print "Enter File Name To Parse: ";			#instructions for entering file
name
$filename = <STDIN>;					#enter file name to parse
print "Enter Output File Name: ";                       #instructions
for entering output file name
$statsfile = <STDIN>;                                   #enter output
file name
open (INFILE, "$filename");				#open input file
while ($line = <INFILE>)				#primary loop
{
 if ($line =~ m/.*\d{6}/)
  
  {
    my ( $vendor, $price, $addr ) =
         unpack 'x11 A7 x10 A10 x11 A25', $line;
       $price =~ tr/$,//d;                            #remove $ and
comma on
price                                                                  
$addr =~ s/^\s+|\s+$//g;                 #whitespace cleanup on
address                 
       &writestatsfile unless $line !~ m/.*\d{6}/;    #only call
subroutine if valid line to prase
                                                          
  }
}
close (INFILE);	#close input file

### SUBROUTINE TO PRINT VENDOR ID, PRICE & ADDRESS TO ASCII .CSV FILE
sub writestatsfile
  {
   open (FILE ,">>$statsfile");                 #open output file for
append
   print FILE "$vendor,$price,\"$addr\"\n";     #write data to file
   close (FILE);						#close output file
  }
# END OF PERL SCRIPT


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

Date: Thu, 17 May 2001 22:24:07 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Match Parsing Glitch
Message-Id: <slrn9g91u7.r9i.tadmc@tadmc26.august.net>

[ text rearranged into a normal time sequence ]

Eric <nospam@xx.com> wrote:
>Jay Tilton wrote:
>> On Thu, 17 May 2001 17:01:39 -0700, Eric <nospam@xx.com> wrote:


>>   my (undef, $vendor, undef, $price, undef, $addr) =
         0      1        2      3       4      5

>>      unpack 'A11 A7 A10 A10 A11 A25', $_;


>Thanks, Jay, but tried this and get the following error:
>
>   Can't declare undef operator in my at [filename.pl] ........


You have an old version of perl. What does "perl -v" say?


>Do I have to make some further assignments or somthing???  


You can use a "list slice" to snatch out the "interesting"
parts of the list returned from unpack().

  my($vendor, $price, $addr) = (unpack 'A11 A7 A10 A10 A11 A25', $_)[1, 3, 5];
                                            1      3       5

or you can waste dummy variables instead of the undefs:

  my ($dummy1, $vendor, $dummy2, $price, $dummy3, $addr) = 
     unpack 'A11 A7 A10 A10 A11 A25', $_;


>Looked up
>'unpack' in my Programming Perl book but am lost here.
                                                  ^^^^

Your problem does not have to do with unpack(). Jay's code uses
a new feature not supported in your version of perl. List slices
have been around for a long time, they should work.


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


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

Date: Fri, 18 May 2001 03:28:31 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Match Parsing Glitch
Message-Id: <3b04947e.413016803@news.erols.com>

On Thu, 17 May 2001 19:58:04 -0700, Eric <nospam@xx.com> wrote:

>"John W. Krahn" wrote:
><snip>
>
>Hi John:
>
>What on earth am I missing???  Here's the entire script.

[...]
>{
[...]
> if ($line =~ m/.*\d{6}/)
>  {
>    my ( $vendor, $price, $addr ) =
>         unpack 'x11 A7 x10 A10 x11 A25', $line;
>       $price =~ tr/$,//d;                              #remove $ and
[...]
>       &writestatsfile unless $line !~ m/.*\d{6}/;    #only call
[...]
>  }
>}
[...]
>sub writestatsfile
>  {
>   open (FILE ,">>$statsfile");                            #open output
>   print FILE "$vendor,$price,\"$addr\"\n";              #write data to
>   close (FILE);						#close output file
>  }

That's a scoping issue.  'my' declares $vendor, $price, and $addr to
be lexical, while writestatsfile() is looking for them as globals.

You can eliminate the 'my' to assign values to global variables
$vendor, $price, and $addr,  or pass the values of the lexicals to the
sub as arguments.  For example,

  writestatsfile($vendor, $price, $addr)
    unless $line !~ m/.*\d{6}/;

  sub writestatsfile
    {
     my ( $vendor, $price, $addr ) = @_;
     open (FILE ,">>$statsfile");                            
     print FILE "$vendor,$price,\"$addr\"\n";              
     close (FILE);					
    }



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

Date: Thu, 17 May 2001 20:41:16 -0700
From: Eric <nospam@xx.com>
Subject: Re: Match Parsing Glitch
Message-Id: <3B0499DC.6F115A0A@xx.com>

Jay Tilton wrote:
> That's a scoping issue.  'my' declares $vendor, $price, and $addr to
> be lexical, while writestatsfile() is looking for them as globals.
> 
;0(

> You can eliminate the 'my' to assign values to global variables
> $vendor, $price, and $addr,  or pass the values of the lexicals to the
> sub as arguments.  For example,
> 
>   writestatsfile($vendor, $price, $addr)
>     unless $line !~ m/.*\d{6}/;
> 
>   sub writestatsfile
>     {
>      my ( $vendor, $price, $addr ) = @_;
>      open (FILE ,">>$statsfile");
>      print FILE "$vendor,$price,\"$addr\"\n";
>      close (FILE);
>     }

OK...tnx again, Jay...I redid the $writestatsfile per above but it is
still not working.  I'm dumbfounded!!!  Using it with the substr
suggestion.

Eric


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

Date: Fri, 18 May 2001 03:43:44 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Match Parsing Glitch
Message-Id: <3B049A7D.2D7DB023@acm.org>

Eric wrote:
> 
> "John W. Krahn" wrote:
> <snip>
> 
> Hi John:
> 
> What on earth am I missing???  Here's the entire script. Some of the
> initial lines in the data file(s) to be parsed have some non-data format
> text. Still can't get this to work & get a bunch of "Uninitialized
> chunck..." type error messages.

I'm going to assume from your example data that a valid line is 80
characters long.

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

print 'Enter File Name To Parse: ';     #instructions for entering file
name
chomp( my $filename = <STDIN> );        #enter file name to parse
print 'Enter Output File Name: ';       #instructions for entering
output file name
chomp( my $statsfile = <STDIN> );       #enter output file name
open INFILE, "< $filename" or die "Cannot open $filename: $!";
open FILE, ">> $statsfile" or die "Cannot open $statsfile: $!";

while ( <INFILE> ) {
    chomp;
    if ( /^\d{3} \d{6}/ and length == 80 ) {
        my ( $vendor, $price, $addr ) = unpack 'x11 A7 x10 A10 x11 A25',
$_;
        $price =~ tr/$,//d;

        print FILE qq($vendor,$price,"$addr"\n);
        }
    }
close FILE;
close INFILE;
__END__



John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 17 May 2001 20:50:33 -0700
From: Eric <nospam@xx.com>
Subject: Re: Match Parsing Glitch
Message-Id: <3B049C09.D36646B0@xx.com>

Tad McClellan wrote:
> 
> You have an old version of perl. What does "perl -v" say?

5.003_07 which I must use as is to complete this task tonight!
> 
> You can use a "list slice" to snatch out the "interesting"
> parts of the list returned from unpack().
> 
>   my($vendor, $price, $addr) = (unpack 'A11 A7 A10 A10 A11 A25', $_)[1, 3, 5];
>                                             1      3       5
> 
> or you can waste dummy variables instead of the undefs:
> 
>   my ($dummy1, $vendor, $dummy2, $price, $dummy3, $addr) =
>      unpack 'A11 A7 A10 A10 A11 A25', $_;

Tnx much, Tad...I tried BOTH of the above, but am still getting the
error message now:
  
  "Use of uninitialized value at stats5.pl line 22, <INFILE> chunck
[[[then a line number for each of the 175 lines in my 1st data file to
parse]]]

ARRRRGGGGGHHHHHHHH!!!!

Eric


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

Date: Fri, 18 May 2001 01:57:10 +0200
From: "Frank van Geesink" <vGeesink@Planet.NL>
Subject: Need Example creating Registry variable names
Message-Id: <9e1o41$6sd5p$1@reader02.wxs.nl>

Hello,

I started last week with programming Perl on my NT machine. After some
starting problems it's going allright. Problem often is to find the correct
information about functions and parameters that can be used. I now have a
problem that I have to create some registry keys.
I'm able to generate subkeys in the registry, also changing the values is
going allright. But the thing that I'm missing is the option were I can add
a variable name in the registry. Here is the test I'm working on.

use Win32::Registry;
my $Register="Software\\Funstuff";
my $hkey, $SubKey;

$HKEY_LOCAL_MACHINE->Open($Register,$hkey) || die $!;
$Key="Frank";
$hkey->Create($New,$SubKey);
$hkey->SetValue($Key,REG_SZ,'Hello');
$hkey->Close();

The program creates a subkey "Frank" an places a default variabele with the
value "Hello". I would like to give this value a name so I get in subkey
"Frank" a variable named "Isay" with the value "Hello". Are there other
optios then $SubKey, I.e. $SubVar?
Can somebody give me a hand?

Thanks,


Frank van Geesink.





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

Date: Fri, 18 May 2001 01:03:14 +0000 (UTC)
From: inwap@best.com (Joe Smith)
Subject: Re: POP3Client
Message-Id: <9e1sci$46v$1@nntp1.ba.best.com>

In article <3add3fcc.2198896@news.planet.nl>, Daneman <lists@planet.nl> wrote:
>an error asking for 
>auto/Mail/POP3Client/delete.al
>
>I know .pl, .pm, .cgi etc files but what is this .al file?! And 
>where do I obtain it? (cannot find it on CPAN anyway..).

Mail::POP3Client is a AutoLoader.  If you invoke a function not defined
in POP3Client.pm, AutoLoader will attempt to auto load it from the .al file.

You've run into an undefined function due to an error in your program.

You will need to re-read the docs; Mail::POP3Client does not have
a function named delete (in all lower case).
	-Joe

P.S. CC sent to developer.  @ISA should not include AutoLoader because
there is nothing after =cut in this module.

--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: Thu, 17 May 2001 16:35:48 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Random Numbers Script
Message-Id: <3B046054.FC4BDFFE@stomp.stomp.tokyo>

sas wrote:
 
> Does anyone have a script that will generate random numbers? Someone told me
> I could do it with Perl but I don't know where to start. It must be a 5
> digit random number which will be associated with a specific name, (an "ID"
> number), I want to check against a log file to be sure the number hasn't
> been used already and then add the number and associated name to that log
> file.  Any help will be greatly appreciated.


This is the second post of your article within the past
month. My presumption is you are not satisfied with the
numerous answers provided the first go-around.

I am going to ignore your parameter of five digits
and post some code this time rather than discussion
only, as I posted last time I answered your article.
Perhaps you will not post this article a third time,
in turn. Maybe, you think?

There is a better method than use of random numbers.
This method of mine does not require opening of a
log file to check for pre-existing numbers. My method
provides automatic sorting both numerically and by
creation date of an entry. It assures no two numbers
will be the same. This method is very simple, very 
fast and very efficient. It is an easy and rather
quick method of using epoch seconds.

My test script below my signature includes a sleep
method to highlight how you can control data base
entries if needed. Should you be making entries
only occasionally, there is no need for a sleep.
You may also write code to turn this sleep function
on and off, at will. This is exceptionally easy.
My hunch is you have no need for a sleep function.
I doubt you will be running large batch files of
entries. If you were, you wouldn't be here asking.
You would be looking at binary executable software
for commercial applications.

There will be a major numerical rollover of epoch
seconds in September. This does not present any
significant problem if you allow one extra space
in your data base for an added digit. This should
not be a problem anyhow; a logical database does
not use space padding nor restricted formatting.

This second time around, why don't you select a few
methods provided by many people and, try them? You
will not be provided with any different answers by
returning and asking a third time.

This line is the heart of my code in conjunction
with the timelocal module.

  print timelocal (localtime()), "\n"; sleep (1)

Godzilla!
--

#!perl

use Time::Local;

print "Content-type: text/plain\n\n";

for ($iterate = 0; $iterate <= 6; $iterate++)
 { print timelocal (localtime()), "\n"; sleep (1) }

exit;

PRINTED RESULTS:
________________

990140344
990140345
990140346
990140347
990140348
990140349
990140350


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

Date: Fri, 18 May 2001 09:33:52 +0930
From: Chris <rebelvideo@hotmail.com>
Subject: Re: Sending wav-file through perl-script
Message-Id: <3B0466E8.2AE9BC8@hotmail.com>

G'day

> True problem is browsers not being able to recognize
> content type by extension and, assign a correct extension
> based on content type. My opinion is browsers should be
> able to assign an extension based on content type, such
> as mid, ra, ru, wav and others.

You are right, perhaps all it would take is the adoption of mime

in a multipart message the filename is included as part of the message 

My biggest complaint in this area is that if the browser doesn't get a
content-type it ASSUMES the content is text and mangles it accordingly

whoever made that stupendous blunder has caused countless headaches and
cost the community huge gobs of bandwidth as people mindlessly continue
to redownload the same file corrupting it in the process!!!!

But Hey arent we a little of topic :)

Chris

<snip>


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

Date: Thu, 17 May 2001 17:30:49 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Sending wav-file through perl-script
Message-Id: <3B046D39.608BEF83@stomp.stomp.tokyo>

Chris wrote:

> > True problem is browsers not being able to recognize
> > content type by extension and, assign a correct extension
> > based on content type. My opinion is browsers should be
> > able to assign an extension based on content type, such
> > as mid, ra, ru, wav and others.
 
> You are right, perhaps all it would take is the adoption of mime
 
(snipped encouragement to beat browser programmers with a kitchen spatula)

Say, Intel has the Blue Man Group. They are great mimes!!
Maybe they are here to save the day!

Godzilla!


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

Date: Fri, 18 May 2001 02:28:29 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Sending wav-file through perl-script
Message-Id: <Pine.LNX.4.30.0105180222210.17324-100000@lxplus003.cern.ch>

On Fri, 18 May 2001, Chris wrote:

> > based on content type. My opinion is browsers should be
> > able to assign an extension based on content type, such
> > as mid, ra, ru, wav and others.
>
> You are right, perhaps all it would take is the adoption of mime

You seem to be advocating the opposite.  MIME informs the recipient
via the content-type information.  File naming conventions are to be
considered non-portable.

> in a multipart message the filename is included as part of the message

I must say I think you're focussing on the wrong issue.  Check the
relevant RFCs for how the filename might be appropriately used at the
other end.

> My biggest complaint in this area is that if the browser doesn't get a
> content-type it ASSUMES the content is text and mangles it accordingly

May we see an example of this happening?  I can't help suspecting
you're confusing with the default _server_ assumption, and subsequent
creation of a text/plain content-type by the server.

> whoever made that stupendous blunder has caused countless headaches

It's easily solved: configure your server to send
application/octet-stream as the default instead.  Then wait for the
complaints to roll in.

> But Hey arent we a little of topic :)

Yes.  f'ups prophylactically set.




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

Date: Thu, 17 May 2001 23:00:12 GMT
From: "Dave" <djm@spamfree.mcoe.k12.ca.us>
Subject: Re: Writing to Unix passwd
Message-Id: <0KYM6.192$1R4.6962@typhoon.sonic.net>

Obviously you are trying to change  a users password, so try this out for
size:


chomp(@encpwd = qx!/bin/encrypt $newpass!);
qx! usermod -p $encpwd $username !;


If you dont have encrypt or usermod, I'm SURE you'll be able to pick them up
after a short search.  It will save you time in the long run...
You need to wrap the above in some protections, but you get the idea...




"Neil A. Beardsley" <nabeards@wpi.edu> wrote in message
news:Pine.OSF.4.33.0105171244590.27644-100000@bert.WPI.EDU...
> Hi,
>
> I'm trying to use the Unix/Linux command passwd from a script.  I used
> open, and try to print to it, but it doesn't work.  Are there any other
> ways to do this?  Does anyone know of a module to perform this?
>
> Here's the code:
>
> open(PASSWD, "|passwd $username") || die "Can't fork to passwd: $!";
> local $SIG{PIPE} = sub { die "Passwd pipe broke." };
> print PASSWD "$password" || die "Can't write password.";
> print PASSWD "$password" || die "Can't write password 2.";
> close PASSWD || die "Failed to close: $!  $?";
>
> Thanks for any help,
> Neil
>




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

Date: Thu, 17 May 2001 18:54:21 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Writing to Unix passwd
Message-Id: <slrn9g8lkt.r2q.tadmc@tadmc26.august.net>

Dave <djm@spamfree.mcoe.k12.ca.us> wrote:

>Obviously you are trying to change  a users password, so try this out for
>size:
>
>chomp(@encpwd = qx!/bin/encrypt $newpass!);
                    ^^^^^^^^^^^^

You should not shell out for things easily accomplished in native Perl.

   perldoc -f crypt


>If you dont have encrypt 

That's fine, because you do not need it if you have Perl  :-)



[snip Jeopardy quoted text (particularly ominous when something
 as important as security might be involved...)
]

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


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

Date: 18 May 2001 01:42:17 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: Writing to Unix passwd
Message-Id: <990150048.982887@elaine.furryape.com>

In article <slrn9g8lkt.r2q.tadmc@tadmc26.august.net>,
Tad McClellan <tadmc@augustmail.com> wrote:
>Dave <djm@spamfree.mcoe.k12.ca.us> wrote:
>
>>Obviously you are trying to change  a users password, so try this out for
>>size:
>>
>>chomp(@encpwd = qx!/bin/encrypt $newpass!);
>                    ^^^^^^^^^^^^
>
>You should not shell out for things easily accomplished in native Perl.
>
>   perldoc -f crypt

Even more importantly, You should not shell out to the wrong program...

encrypt(1) is a bi-directional encryption scheme based upon The Enigma
Machine.

crypt(3) is a one-direction hash, based upon DES.


Despite the similar names, they're not interchangable.



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

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


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