[11703] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5303 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 5 18:06:23 1999

Date: Mon, 5 Apr 99 15:00:17 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 5 Apr 1999     Volume: 8 Number: 5303

Today's topics:
    Re: Can some one debug this perl - I need help (Sam Holden)
    Re: Communicating with a C shell script <ddelikat@protix.com>
    Re: constructing a list of hashes <jglascoe@giss.nasa.gov>
    Re: constructing a list of hashes <gisle@aas.no>
    Re: constructing a list of hashes <uri@home.sysarch.com>
    Re: constructing a list of hashes <uri@home.sysarch.com>
    Re: Form Submission - Multi <emschwar@rmi.net>
    Re: here docs vs qq quote operator. Just personal prefe <upsetter@ziplink.net>
    Re: here docs vs qq quote operator. Just personal prefe (Ilya Zakharevich)
    Re: here docs vs qq quote operator. Just personal prefe <uri@home.sysarch.com>
    Re: here docs vs qq quote operator. Just personal prefe (Sean McAfee)
    Re: How to print n times a character? (Tyler Hutcheon)
    Re: HTTP document transfers <cassell@mail.cor.epa.gov>
    Re: HTTP document transfers <infomage@infomage.force9.co.uk>
    Re: Not stupid anymore (Bart Lateur)
    Re: perl and y2k (was Re: The millennium cometh -- even (George)
    Re: Premature end of script headers <cassell@mail.cor.epa.gov>
    Re: Premature end of script headers <infomage@infomage.force9.co.uk>
        Question regarding databases and unwanted data build-up (George)
    Re: splice incompatible with foreach <cassell@mail.cor.epa.gov>
    Re: Still stupid I guess. (Bart Lateur)
    Re: Time Functions in Perl ! (Larry Rosler)
    Re: Unpack Question <ddelikat@protix.com>
    Re: Why does Perl do this? (George)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 5 Apr 1999 21:07:23 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Can some one debug this perl - I need help
Message-Id: <slrn7gi9gb.gjk.sholden@pgrad.cs.usyd.edu.au>

On Mon, 5 Apr 1999 22:24:43 +0200, ACE Alex <alex@saers.com> wrote:
>Uhh, what? Can you compile perl scripts to binarys?

Every time a perl script gets run it gets compiled to binary...
of course it was in binary to begin with...
unless your computer uses trinary of course...

-- 
Sam

Even if you aren't in doubt, consider the mental welfare of the person
who has to maintain the code after you, and who will probably put parens
in the wrong place.	--Larry Wall


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

Date: Mon, 05 Apr 1999 16:16:49 -0500
From: David Delikat <ddelikat@protix.com>
Subject: Re: Communicating with a C shell script
Message-Id: <37092841.ABD@protix.com>

menardm@my-dejanews.com wrote:
> 
> I have a perl cgi script that I'm using to kick off a C shell script
> (ultimately I could rewrite the Csh script code and add its functionality to
> the perl script, but thats not a time option right now).  The Csh script
> previously ran from the command line.  It is interactive, and asks the user
> various questions and according to the answer does different things (no
> kidding).  I'm having trouble getting the perl script and the Csh script to
> communicate properly.  I can get the Csh script output to appear, but when
> the Csh script asks a question (using $< ) I can't that communication path
> working correctly.  I've tried using the open command with a pipe
> (open(filehandle , "command |")) and I've also tried the open2 subroutine
> (open2(readfilehndl, writefilehndl, "command")) with no success.  Any
> Ideas....
> 
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own

My initial reaction is that you will save yourself more time
by re-writing the csh script in perl.

my second reaction is that you need to look at you csh documentation
to figure out what that symbol (   $<   ) really does.

-dav

-- 
<((((><
Consultant: Internet, Database, Business Systems
Unix/Linux, Windows95/NT
mailto:david-delikat@usa.net / http://obj.webjump.com/


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

Date: Mon, 05 Apr 1999 17:13:38 -0400
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: Sean McAfee <mcafee@waits.facilities.med.umich.edu>
Subject: Re: constructing a list of hashes
Message-Id: <37092782.F7116697@giss.nasa.gov>

[courtesy copy of post sent to Sean McAfee and Larry Rosler]

Sean McAfee wrote:
> 
> What version of Perl are you using?  It's 5.005_02 for me.

perl5.005_55

let me reduce this thing to its essence:

$ perl -e '
    %hash = (1=>"one");
    $_ = "uno" foreach values %hash;
    print $hash{1}, "\n";
'

I get "uno".  Really.  :o)
Larry Rosler quotes the perlsyn manpage:

> "If any element of LIST is an lvalue, you can modify it by modifying VAR
> inside the loop. That's because the foreach loop index variable is an
> implicit alias for each item in the list that you're looping over."

and then points out that each element of "values %hash"
is an *rvalue*.  So, although the first sentence doesn't
say "only if", maybe this feature should be removed
from perl5.005_55 ?

	Jay Glascoe


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

Date: 05 Apr 1999 23:24:48 +0200
From: Gisle Aas <gisle@aas.no>
Subject: Re: constructing a list of hashes
Message-Id: <m3677ahian.fsf@eik.g.aas.no>

lr@hpl.hp.com (Larry Rosler) writes:

> > no, "$_" is bound to each value from from the hash.
> > Try this:
> > 
> > @hash{'A' .. 'H'} = (1..8);
> > 
> > print "$_ => $hash{$_}\n" foreach sort keys %hash;
> > print "\n";
> > 
> > $_ = 0 foreach values %hash;
> > print "$_ => $hash{$_}\n" foreach sort keys %hash;
> 
> I am sure you tried this program before you posted it.  But you must be 
> using a different version of perl from anyone else.  It doesn't change 
> any hash values when I try it.

It should work for perl >= 5.005_52, because of this patch:
____________________________________________________________________________
[  1819] By: gsar                                  on 1998/09/23  06:08:46
        Log: make \(%foo) return refs to values (not copies of values)
             From: Stephen McCamant <smccam@uclink4.berkeley.edu>
             Date: Fri, 28 Aug 1998 20:46:10 -0700 (PDT)
             Message-ID: <13799.30680.47765.352558@fre-76-120.reshall.berkeley.edu>

> Someone else thought the same thing *yesterday*, and tried to change the 
> keys of a hash by aliasing.  It didn't work any better than it does for 
> the values of a hash.  I'll just quote my previous answer verbatim; 
> s/keys/values/g in the last paragraph;

keys %hash can't be made to return references to the keys, because
they are not represented as real perl values.  See
http://gisle.aas.no/perl/illguts-0.07/#hv

-- 
Gisle Aas


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

Date: 05 Apr 1999 17:27:35 -0400
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: constructing a list of hashes
Message-Id: <x7emlyvjug.fsf@home.sysarch.com>

>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:

  LR> [Posted and a courtesy copy mailed.]
  LR> In article <370918A1.3C6378AB@giss.nasa.gov> on Mon, 05 Apr 1999 
  LR> 16:10:09 -0400, Jay Glascoe <jglascoe@giss.nasa.gov> says...
  >> 
  >> $_ = 0 foreach values %hash;
  >> print "$_ => $hash{$_}\n" foreach sort keys %hash;

  LR> I am sure you tried this program before you posted it.  But you must be 
  LR> using a different version of perl from anyone else.  It doesn't change 
  LR> any hash values when I try it.


this should be an FAQ already. the trick is to use a hash slice:


$_ = 0 foreach @hash{keys %hash} ;

since that creates a list of lvalues (the values BTW, not the keys)
which can be aliased to $_.

it makes no sense to do the same or something similar with the values
func.

but if that is all you want to do then a simpler method is:


@hash{keys %hash} = (0) x (keys %hash / 2);

the /2 might even be optional if you don't mind generating a longer list
of (0) and throwing the second part away in the assignment.

@hash{keys %hash} = (0) x keys %hash ;

hth,

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: 05 Apr 1999 17:46:19 -0400
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: constructing a list of hashes
Message-Id: <x790c6viz8.fsf@home.sysarch.com>

>>>>> "JG" == Jay Glascoe <jglascoe@giss.nasa.gov> writes:

  JG> [courtesy copy of post sent to Sean McAfee and Larry Rosler]
  JG> Sean McAfee wrote:
  >> 
  >> What version of Perl are you using?  It's 5.005_02 for me.

  JG> perl5.005_55

  JG> let me reduce this thing to its essence:

  JG> $ perl -e '
  JG>     %hash = (1=>"one");
  JG>     $_ = "uno" foreach values %hash;
  JG>     print $hash{1}, "\n";
  JG> '

  JG> I get "uno".  Really.  :o)
  JG> Larry Rosler quotes the perlsyn manpage:

  >> "If any element of LIST is an lvalue, you can modify it by modifying VAR
  >> inside the loop. That's because the foreach loop index variable is an
  >> implicit alias for each item in the list that you're looping over."

  JG> and then points out that each element of "values %hash"
  JG> is an *rvalue*.  So, although the first sentence doesn't
  JG> say "only if", maybe this feature should be removed
  JG> from perl5.005_55 ?

that is an unstable version of perl. maybe it will work in 5.003 when it
comes out. until then it is not a correct method to use for most people
with <= 5.005_02. also according to Gisle Aas, that works because of a
patch to something else. it may be an undocumented bug/feature/byproduct
of that patch. so i wouldn't rely upon it for any production work.

see if your version of perlsyn for values covers that use as an list of
lvalues.

i posted a method that works for all versions.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: 05 Apr 1999 15:53:47 -0600
From: Eric The Read <emschwar@rmi.net>
Subject: Re: Form Submission - Multi
Message-Id: <xkfogl2ag44.fsf@valdemar.col.hp.com>

"Bruce Davidson" <bruce.d@btinternet.com> writes:
> Is there any way to submit the variables from one cgi generated form to two
> different scripts which occupy two different frames.

Is there any reason you didn't ask this in comp.infosystems.www.cgi,
where it's appropriate?

-=Eric.  It's a rhetorical question, see?


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

Date: Mon, 05 Apr 1999 21:08:24 GMT
From: Scratchie <upsetter@ziplink.net>
Subject: Re: here docs vs qq quote operator. Just personal preference?
Message-Id: <cD9O2.1164$eJ.201957@news.shore.net>

Abigail <abigail@fnx.com> wrote:
: -- Using here docs is suggested a lot more than simple quote operators and I was
: -- wondering if there is an advantage or just out of habit?


: The big advantage here docs have over quoted strings is that you can 
: actually finish your statement before starting the large string.

Someone else (Uri?) pointed out that you never have to escape your quote
character with here docs either, which is also an advantage. But I agree
that in most cases I find qq and q a little easier to use.

--Art
-- 
--------------------------------------------------------------------------
                    National Ska & Reggae Calendar
                  http://www.agitators.com/calendar/
--------------------------------------------------------------------------


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

Date: 5 Apr 1999 21:09:57 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: here docs vs qq quote operator. Just personal preference?
Message-Id: <7eb8r5$8b9$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Sam Holden
<sholden@cs.usyd.edu.au>],
who wrote in article <slrn7gi5ud.fdc.sholden@pgrad.cs.usyd.edu.au>:
> >> perl -wleprint -eqq-@{[ -eqw\\\\- -eJust -eanother -ePerl -eHacker -e\\\\-]}-
> >
> >OK, what's up Abigail, that one didn't work.  I just copy and paste
> >in another X session and it gives me lots of perl errors.
> 
> Abigail is just trying to lull people into doing 'copy and paste' with
> the sigs. So that one day what will go down in history as the 'perl worm'
> will be unleashed, as thousands of people on thousands of servers execute
> arbitrary code posted to usenet by someone they have never met...

NO.  You wanted to write:

  So that one day what will go down in history the 'perl worm' in 3
  lines of perl will be unleashed in somebody's signature.

Ilya


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

Date: 05 Apr 1999 17:40:41 -0400
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: here docs vs qq quote operator. Just personal preference?
Message-Id: <x7bth2vj8m.fsf@home.sysarch.com>

>>>>> "S" == Scratchie  <upsetter@ziplink.net> writes:

  S> Abigail <abigail@fnx.com> wrote:
  S> : -- Using here docs is suggested a lot more than simple quote operators and I was
  S> : -- wondering if there is an advantage or just out of habit?


  S> : The big advantage here docs have over quoted strings is that you can 
  S> : actually finish your statement before starting the large string.

  S> Someone else (Uri?) pointed out that you never have to escape your quote
  S> character with here docs either, which is also an advantage. But I agree
  S> that in most cases I find qq and q a little easier to use.

i did, and i stand by that as well as the advantage (which abigail and
others mentioned) of having a complete perl statement together rather
than stretched out over multiple lines when using a long string with q
or qq. as i also said, q/qq and here docs have different behaviors
regarding the leading and trailing whitespace. i may write an FAQ on
this one too. quoted strings is one area we seem to get too many FAQ
about. here docs are just another quoted string syntax.

i use all string flavors ', ", q, qq, << as needed. each has its place
and all should be clearly understood by any perl hacker worthy of that
name.

what i hate most is seeing " used on strings without any interpolation
needed.  this is like the use of /s in regexes and no use of . in
them. it is semantically misleading to the reader of the code and makes
for harder maintenence later on. also backslashitis is painful to read
as well as multiple print calls in a row. learn your string literals!

i know larry made perl strings as flexible as syntactically possible
(yeah!) but people coming from other languages never seem to grasp how
to use all the quote styles. 

here docs are called that because of their ancestry from sh. there they
were documents that were 'here' and not in a file, that were fed into
stdin. perl uses them as alternative string quotes and should use a
different name. i have seen word/line delimited/quoted strings. any
ideas on a better term for them?

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Mon, 05 Apr 1999 21:56:03 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: here docs vs qq quote operator. Just personal preference?
Message-Id: <TjaO2.1311$9Y5.6849189@news.itd.umich.edu>

In article <x7bth2vj8m.fsf@home.sysarch.com>,
Uri Guttman  <uri@home.sysarch.com> wrote:
>what i hate most is seeing " used on strings without any interpolation
>needed.

Early in my Perl career I went through a phase when I religiously used
double quotes only when interpolation made them necessary.  It didn't last
long, because it was really irritating switching quote types whenever I
needed to add an interpolated variable or escape sequence to a single-quoted
string, or remove the last interpolated variable or escape sequence from
a double-quoted string.  To avoid this hassle, I tend to use double quotes
everywhere.

>also backslashitis is painful to read
>as well as multiple print calls in a row. learn your string literals!

Amen, brother!

-- 
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: Mon, 05 Apr 1999 21:44:22 GMT
From: hutcheon@iaw.on.ca (Tyler Hutcheon)
Subject: Re: How to print n times a character?
Message-Id: <37092e66.4175023@news.iaw.on.ca>

On Mon, 05 Apr 1999 12:59:23 +0200, Federico Abascal
<fabascal@gredos.cnb.uam.es> wrote:

>Please I don't remember how to do it and where I saw how it has to be
>done?
>Can you help me?
>Thanks, Fede

try:
print "hi " x 80;

"hi " being the quote
x being the multiplyer
and 80 being the amount of times

Tyler Hutcheon
hutcheon@iaw.on.ca


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

Date: Mon, 05 Apr 1999 14:03:25 -0700
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: HTTP document transfers
Message-Id: <3709251D.DFC08D92@mail.cor.epa.gov>

Infomage wrote:
> > Use the libwww module e.g.
> >
> > use LWP::Simple;
> > $doc = get 'http://www.sn.no/libwww-perl/';
> >
> > The above is straight from the docs ('lwpcook').
> >
> > HTH.
> >
> 
> OK...  Have tried that in many guises...  The problem I am getting is
> that I need to use an intermediate variable as the actual URL will
> potentially be different each time the script runs.
> 
> As it is, I just get an empty return from the 'get' command, and then
> when I run using the -w flag, I get messages complaining of an undefined
> variable.  (The one that *should* be filled with the output from the
> 'get')
> 
> <Pulling out hair>     ...      </Pulling out hair>

Okay, take a deep breath, and let go of that hair.  Alopecia is
a common problem in computer programming, but you don't need to
encourage it.  :-)

The best thing you can do is show us some of the code [complete 
enough to test ourselves] that is bombing for you.  We can't tell
from here.  It may be as simple as your using single quotes (which
don't interpolate variables) when you really want double quotes
around your variable containing the URL.  The problem may be else-
where, though.

David
-- 
David L. Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Mon, 05 Apr 1999 22:26:53 +0100
From: Infomage <infomage@infomage.force9.co.uk>
Subject: Re: HTTP document transfers
Message-Id: <37092A9C.D921C04C@infomage.force9.co.uk>



"
> The best thing you can do is show us some of the code [complete
> enough to test ourselves] that is bombing for you.  We can't tell
> from here.  It may be as simple as your using single quotes (which
> don't interpolate variables) when you really want double quotes
> around your variable containing the URL.  The problem may be else-
> where, though.
> 
> David
> --
> David L. Cassell, OAO                     cassell@mail.cor.epa.gov
> Senior computing specialist
> mathematical statistician


#!/usr/bin/perl
$MessNum = $ARGV[0];  # Get the Message Number from the command line
chomp ($MessNum);
$TheMain = '';
use LWP::Simple;
$inter = 'http://www.starlightlines.com/cgi-bin/messageread/emp/' .
$MessNum . "\n";

print $inter;

$TheMain = get "$inter";  # Get the main page
 ... ...

<snip>

Please feel free to point out the stupid mistake....  :o)


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

Date: Mon, 05 Apr 1999 21:14:18 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Not stupid anymore
Message-Id: <370a2774.1027317@news.skynet.be>

Rob Sweet wrote:

> The
>web admin at the destination had misled me, claiming that their site
>wouldn't work if I posted direct to the CGI.

What a "clever" webmaster. Sheesh.

	Bart.


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

Date: Mon, 05 Apr 1999 17:21:46 -0400
From: fred222@mauimail.com (George)
Subject: Re: perl and y2k (was Re: The millennium cometh -- eventually)
Message-Id: <fred222-ya023580000504991721460001@news.bellatlantic.net>

In article <19990331.215239.5N7.rnr.w164w@locutus.ofB.ORG>, Russell Schulz
<Russell_Schulz@locutus.ofB.ORG> wrote:

> "David L. Cassell" <cassell@mail.cor.epa.gov> writes:
> 
> >> again:  this is why I disagree with the FAQ.  I have never seen a
> >> pencil that would surprise a user (who, shockingly, hadn't memorized
> >> its manual) by writing 100 when referring to 2000.
> >
> > Oh no!  He's right!  All programming languages are Y2K noncompliant,
> > since someone somewhere can misuse them!
> 
> I see a big difference between `can misuse' and `will misuse, if using the
> natural way provided'.
> 
> Does your response mean:
> 
>   a. You don't understand this difference?
>   b. You don't think the difference is real?
>   c. You think the difference won't affect real code?
>   d. You just wanted to make a Unabomber post?
>   e. Other...?
> -- 
> Russell_Schulz@locutus.ofB.ORG  Shad 86c

The fact of the matter is, it's not that big of a deal to change the date
from 100 to 2000.  Here's the code I've used again and again.. it works for
me, but no guarantees about its greatness, eh? ;-)

####CODE START####
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$unix_time = time();
@months =
("Jan.","Feb.","Mar.","Apr.","May","June","July","Aug.","Sep.","Oct.","Nov.",
"Dec.");

$is_2000 = 0;
if ($year>=100) { $is_2000 = 1;
               $year = $year - 100; }
if ($year<10) { $year = "0" . "$year"; }
if ($is_2000) { $year = "20" . "$year"; }
if ($year<100) { $year = "19" . "$year"; }

$date = "$months[$mon] $mday $year";
####CODE END######

That gives a nicely formatted date.. like 1999 or 2003.. could add a
weekday name like the month name by just making a
'sunday,monday...etc...friday,saturday' array and using $wdaysarray[$wday].

Best regards,
George Henry

-- 
Just another hacking head >l-d


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

Date: Mon, 05 Apr 1999 14:06:57 -0700
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: Premature end of script headers
Message-Id: <370925F1.6BFF461C@mail.cor.epa.gov>

Infomage wrote:
> <snip>
> 
> Just a little suggestion that you may or may not be aware of...
> 
> It is *essential* that when you upload your script, you send it in ASCII
> mode rather than Binary.  This prevents the FTP process replacing
> certain characters which are needed by PERL to interpret the script
> correctly.
> 
> I have heard many people complaining of this problem, and when ASCII
> protocol is used, the problem ceases.
> 
> :o)

Good point.  BTW, you might be interested that Perl is traditionally
spelled with one cap and three lowercased letters.. even though it
is an acronym.  That was done on purpose to warn the unwary.  :-)

David
-- 
David L. Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Mon, 05 Apr 1999 22:21:05 +0100
From: Infomage <infomage@infomage.force9.co.uk>
Subject: Re: Premature end of script headers
Message-Id: <37092941.287A70D9@infomage.force9.co.uk>



"David L. Cassell" wrote:
> 

> Good point.  BTW, you might be interested that Perl is traditionally
> spelled with one cap and three lowercased letters.. even though it
> is an acronym.  That was done on purpose to warn the unwary.  :-)
> 
> David
> --
> David L. Cassell, OAO                     cassell@mail.cor.epa.gov
> Senior computing specialist
> mathematical statistician


Duly noted.  Thanks.  <g>

BTW, did you catch my later thread?  I am still seeking advice...


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

Date: Mon, 05 Apr 1999 17:14:24 -0400
From: fred222@mauimail.com (George)
Subject: Question regarding databases and unwanted data build-up
Message-Id: <fred222-ya023580000504991714240001@news.bellatlantic.net>

I have been working on a site which uses a lot of databases - several
thousand.  Some are member databases, and some are for jokes.  When the
member databases are modified (they are very often, since I count stuff
like the number of jokes read and so forth) I use code much like the
following:

######
open(DAT,"+<members/$user.db");
flock DAT, 2;
@member_array = split(/\|/,<DAT>);
$member_array[29]++;
$newmemline = join("\|",@member_array);
seek(DAT,0,0);
print DAT "$newmemline";
close(DAT);
######

My question is the following:  I end up with gobbledegook building up at
the end of each database line.  Each file is just one line, with fields
seperated by |'s.  Here is an example of the gunk:

 ...[much deleted]....0.122.205|1||1ime()()()())))))))))))))))))

You see that at the end?  I have no idea where that comes from :P sometimes
I call time() in my script and write it to the database, but not anywhere
near the last array... so i was wondering if, every time I write to the
database, I should do something like:

#####
[code as above up to seek command]
<DAT> = '';
print DAT "$newmemline";
#####

to kill the remnants of the file first before writing the modified info?

In any case, if responses could PLEASE be cross-emailed to me at the
following address (with the NOSPAM deleted of course), I would be most
appreciative:

yurtle@bellatlantic.netNOSPAM

Thanks,
George Henry

-- 
Just another hacking head >l-d


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

Date: Mon, 05 Apr 1999 14:17:51 -0700
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: splice incompatible with foreach
Message-Id: <3709287F.B2DE55DE@mail.cor.epa.gov>

Marshall Dudley wrote:
> 
> I am trying to go through an array and do something with each element,
> and in some cases remove the element from the array.  The splice
> function is the only one I can find to let me do this, but it interacts
> with the foreach so I get screwy results.

Correct.  Don't do that.  Have you tried a visualization of this with
pseudo-code?  When you splice() your array, you diddle the iterator.
If you write the equivalent code in C or Pascal, bad things will happen
there too.

> This simple script is suppose to look at all lines and remove those that
> say remove.  But it completely misses any line after a remove, and
> doesn't always remove the lines with remove in them.  Does anyone know
> an easy solution to getting around this?
> 
> Thanks,
> 
> Marshall
> 
> @lines = ("1 keep","2 keep","3 remove","4 keep","5 remove","6 remove","7
> keep");
> $count = -1;
> foreach $line (@lines) {
>         $count++;
> #do things with that particular $line here then remove some of the lines
> from the array
>         if ($line =~ /remove/) {splice (@lines,$count,1); }
>         print "$line\n";
> }
> print "\n";
> foreach $line (@lines) { print "$line\n"; }

The short way to do this is with the nifty grep() operator.  It takes a
little getting used to for many people, but it's worth learning about.

@subset = grep !/remove/, @lines;

or to make it a *little* clearer, using a block:

@subset = grep { $_ !~ /remove/ } @lines

[keep the lines which don't match /remove/ ]

David
-- 
David L. Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Mon, 05 Apr 1999 21:06:34 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Still stupid I guess.
Message-Id: <3709251e.429019@news.skynet.be>

Rob Sweet wrote:

>What I need to do is have a script programatically fill in the form at
>www.yahoo.com and "click" submit.

The form isn't important. It's the data that gets "posted" that matters!

Try experimenting a little. Take the form, save the source. Replace the
'method ="post"' phrase with 'method="get"'. Maybe change the URL.
Manually fill in some data. Click submit . Now, you'll see the data as
it would have been sent to the CGI, in the URL.

All you have to do now, is construct the very same data, and send them
to the real script. And that's it.

   HTH,
   Bart.


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

Date: Mon, 5 Apr 1999 13:57:05 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Time Functions in Perl !
Message-Id: <MPG.1172c380e3530539989834@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <7eb3u2$9ag$1@nnrp1.dejanews.com> on Mon, 05 Apr 1999 
19:46:11 GMT, rujain@my-dejanews.com <rujain@my-dejanews.com> says...
> The situation is : I have input as timestamp <yyyy-mm-dd> <hh:mm:ss> format.
> I want to convert this timestamp to the unix time format (secs elapsed since
> 1-1-1970). Is there any function in Perl, which will work on Windows-NT and
> UNIX platforms.

  use Time::Local;
  my $unix_time = timelocal(...);

See the documentation for localtime() for the arguments to timelocal().  
There is also a function for GMT.

This is part of the standard perl distributions.  CPAN not needed.

-- 
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Mon, 05 Apr 1999 15:59:52 -0500
From: David Delikat <ddelikat@protix.com>
Subject: Re: Unpack Question
Message-Id: <37092448.FF6@protix.com>

Jason Hissong wrote:
> 
> I am trying to unpack a C structure stored in a binary file that looks
> like this:
> 
> typedef struct  _example
> {
>     unsigned short var_a   :   5,
>                               var_b  :   5,
>                               var_c  :   6;
>     long l_var;
> } EXAMPLE;
> 
> EXAMPLE example;
> 
> What would be my template for grabbing the parts of the unsigned short?
> i.e., getting to example.var_a or example.var_b in PERL?
> 
> My template now looks like this:
> 
> "Sl"
> 
> Thanks!
> 
> Jason Hissong

using unpack to comunicate with C can be stessfull.

I spend a day trying to get my data to transfer successfully.
( 30 some fields. )  essentially if all you have is those
three, yopu only need to determine how each is truely being
stored.  a sizeof(_example) will give you a few clues, like
is the compiler padding the structure.  also take a look at the
binary data that perl is getting.  this should be some simple
detective-work.  however, if your structure is more complicated
( has different sized integers, floats, and strings ) I recommend
re-organizing.  chances are your compiler is trying to optimize
the structure ( if you can turn it off, try that too. )  the best
organization I found was numeric itens first ordered largets bit
count to smallest.  followed by all strings in any particualr order.

basically something like this:

double a,b,c;
long d,e,f;
int g,h,i;
char j,k,l;
char m[32],n[10],o[16];

that will make the required detective work much more basic,
because all of the padding ~should~ be concentrated into the points
between the various types.

good luck

-dav

-- 
<((((><
Consultant: Internet, Database, Business Systems
Unix/Linux, Windows95/NT
mailto:david-delikat@usa.net / http://obj.webjump.com/


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

Date: Mon, 05 Apr 1999 17:27:11 -0400
From: fred222@mauimail.com (George)
Subject: Re: Why does Perl do this?
Message-Id: <fred222-ya023580000504991727110001@news.bellatlantic.net>

> # --- Prog 1 --- #
> 
> some_sub() ;
> print @foo ;                #prints 123 (as expected)
> 
> sub some_sub {
>     @foo = ( 1, 2, 3 ) ;
> }
> 
> # --- Prog 2 --- #
> 
> some_sub() ;
> # @goo = @foo ;      # remove comment and prog 2 works
> print "@foo" ;            #does not print 1 2 3 (as expected)
> 
> sub some_sub {
>     @foo = ( 1, 2, 3 ) ;
> }

When you double-quote it, it tries to print an @ sign instead of printing
each element of the array.  This means when you're writing an HTML page and
you do a mailto, you need to write "mailto:joebob\@wherever.com" - but it
doesn't look for the array whatever, do you follow?  If you wrote "print
@whatever", then it WOULD look for that array and print all its values.

So if you want to print the array, using no quotes or single quotes i think
(') and if you want to actually print an @ sign, do whatever and use an
escape \.

Hope I'm not wrong, and Cheers,
George

-- 
Just another hacking head >l-d


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". 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". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 5303
**************************************

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