[18374] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 542 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 21 14:11:18 2001

Date: Wed, 21 Mar 2001 11:10:24 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <985201823-v10-i542@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 21 Mar 2001     Volume: 10 Number: 542

Today's topics:
    Re: Pointers in Perl (Craig Berry)
    Re: Pointers in Perl <bart.lateur@skynet.be>
    Re: Print "tar" Success or Failure <bmb@ginger.libs.uga.edu>
        Problems with substitutions using regular expressions jbowman@budweiser.com
    Re: Problems with substitutions using regular expressio <jonni@ifm.liu.se>
    Re: Problems with substitutions using regular expressio (John Joseph Trammell)
        Q: usernames & passwords - how to ??? <richard@science.uottawa.ca>
    Re: Q: usernames & passwords - how to ??? <tom@power.net.uk>
    Re: Q: usernames & passwords - how to ??? (Jon Bell)
        question on string identification <u7rjb@csc.liv.ac.uk>
    Re: question on string identification <dave@dave.org.uk>
    Re: Script for mail forwarding? (Miguel Cruz)
    Re: Script for mail forwarding? <bart.lateur@skynet.be>
    Re: Script for mail forwarding? gls@byu.edu
    Re: Script for mail forwarding? (Randal L. Schwartz)
    Re: Script for mail forwarding? (Randal L. Schwartz)
    Re: Script for mail forwarding? (Abigail)
    Re: Script for mail forwarding? (Abigail)
    Re: Script for mail forwarding? <joe+usenet@sunstarsys.com>
    Re: small question - reading/writing data structures to <bmb@ginger.libs.uga.edu>
    Re: small question - reading/writing data structures to <bmb@ginger.libs.uga.edu>
    Re: small question - reading/writing data structures to <bart.lateur@skynet.be>
    Re: substitution/pattern matching -- setting the positi (Miguel Cruz)
        Thanks for hash; how to read command line arguments? (Jim Kroger)
    Re: Thanks for hash; how to read command line arguments <dave@dave.org.uk>
        Threaded Perl on FreeBSD <tick1@my-deja.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 21 Mar 2001 18:15:22 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Pointers in Perl
Message-Id: <tbhrtqrac75jf1@corp.supernews.com>

Milliwave (milliwave@rfengineering.freeserve.co.uk) wrote:
: Has anyone come across the usage of pointers in Perl? I certainly
: have not see these being used.
: Any information on their usage would be greatly appreciated.

There are no pointers as such in Perl.  References can be used for many of
the same purposes.  Also, the containers and access constructs in Perl
typically make the sort of code which uses pointers in other languages
unnecessary.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "When the going gets weird, the weird turn pro."
   |               - Hunter S. Thompson


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

Date: Wed, 21 Mar 2001 18:39:48 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Pointers in Perl
Message-Id: <b7thbtgsbho1hjdmmulod8nhnou86ghvfu@4ax.com>

Milliwave wrote:

>Has anyone come across the usage of pointers in Perl? I certainly have not
>see these being used.

What would you want to do with pointers that you can't do    with
references?

The only good reason I can see to use actual pointers, is when
interfacing to another program or to the OS, via an API. And then, the
interface module will just take the pointer it wants to your scalar,
transparently, or you can use pack/unpack with template 'P' (or 'p') to
do it explicitely.

-- 
	Bart.


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

Date: Wed, 21 Mar 2001 09:46:37 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Print "tar" Success or Failure
Message-Id: <Pine.A41.4.21.0103210944350.17380-100000@ginger.libs.uga.edu>

On Wed, 21 Mar 2001, BUCK NAKED1 wrote:

> Thanks for everyone's time and help. I still haven't figured it out, but
> I can understand  your choosing not to continue this discussion.

Does the following help at all?

     1  #!/usr/local/bin/perl
     2  use warnings;
     3  use strict;
     4
     5  my $success = system('tar cvf x.tar qt paste');
     6
     7  print "\n\$?:$? \$success:$success\n\n";
     8
     9  my $failure = system('tar Z');
    10
    11  print "\n\$?:$? \$failure:$failure\n";
    12
    13  __END__
    14
    15  Output:
    16
    17  a qt 1K
    18  a paste 2K
    19
    20  $?:0 $success:0
    21
    22  tar: Z: unknown option
    23  Usage: tar {txruc}[vfbFXhiBEelmopwnq[0-7]] [snipped by me] ...
    24
    25  $?:256 $failure:256

Brad



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

Date: 21 Mar 2001 14:45:24 GMT
From: jbowman@budweiser.com
Subject: Problems with substitutions using regular expressions
Message-Id: <99aeq4$9oa$1@news.netmar.com>


Hello, I am working on a script that will go through a file and do search and
replaces using terms taken from another file. My problem is that when I do my
searchs, I can search for tabs using '\t' but cannot put a tab in using '\t'.
Example syntax would be:

   working     - s/\t/TABMARKER/g
   not working - s/TABMARKER/\t/g

Working will find all instances of tabs, and change them to the text
TABMARKER.
Not Working will find all instances of TABMARKER and change them to the text
\t.

Is there any way to make Perl so interpetation within the replacement term as
well as the matching term?



 -----  Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web  -----
  http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
   NewsOne.Net prohibits users from posting spam.  If this or other posts
made through NewsOne.Net violate posting guidelines, email abuse@newsone.net


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

Date: Wed, 21 Mar 2001 16:38:31 +0100
From: "Jonas Nilsson" <jonni@ifm.liu.se>
Subject: Re: Problems with substitutions using regular expressions
Message-Id: <99ahp1$1a9$1@newsy.ifm.liu.se>

>    working     - s/\t/TABMARKER/g
>    not working - s/TABMARKER/\t/g
>
> Working will find all instances of tabs, and change them to the text
> TABMARKER.
> Not Working will find all instances of TABMARKER and change them to the
text
> \t.
>

If you want to change all tabs to the string '\t' use
s/\t/\\t/g;

And to change back:
s/\\t/\t/g;
/jN




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

Date: Wed, 21 Mar 2001 18:10:30 GMT
From: trammell@bayazid.hypersloth.invalid (John Joseph Trammell)
Subject: Re: Problems with substitutions using regular expressions
Message-Id: <slrn9bhpmd.ap.trammell@bayazid.hypersloth.net>

On 21 Mar 2001 14:45:24 GMT, jbowman@budweiser.com wrote:
> 
> Hello, I am working on a script that will go through a file and do search and
> replaces using terms taken from another file. My problem is that when I do my
> searchs, I can search for tabs using '\t' but cannot put a tab in using '\t'.
> Example syntax would be:
> 
>    working     - s/\t/TABMARKER/g
>    not working - s/TABMARKER/\t/g

Hmmm.

  [ ~ ] echo "ababab" > foo
  [ ~ ] perl -pi -e 's/a/\t/g' foo 
  [ ~ ] cat foo 
         b       b       b
  [ ~ ] perl -pi -e 's/\t/c/g' foo
  [ ~ ] cat foo
  cbcbcb
  [ ~ ]

Maybe you should post some code.



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

Date: Wed, 21 Mar 2001 09:08:32 -0500
From: "Francois Richard" <richard@science.uottawa.ca>
Subject: Q: usernames & passwords - how to ???
Message-Id: <99ackv$b5u2@mercury.cc.uottawa.ca>

Can someone please point me in the right direction (FAQ, web resources,
etc.)?

I want to create a simple web page that allows guests to the web site to
enter a userid and password, and store these with their names in a text
or database file on our server.

What is the best way to do this? Does it involve JavaScript alone, or a
combination with other tools (CGI, Perl, Java, etc.)?

I have looked for info on the internet, but so far this is proving to be
a very frustrating experience... I would greatly appreciate any
pointers/advice you may have.

Cheers,
_________________________________________________
François Richard  -  Earth Sciences
University of Ottawa (Canada)






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

Date: Wed, 21 Mar 2001 14:19:19 +0000
From: Tom Scheper <tom@power.net.uk>
Subject: Re: Q: usernames & passwords - how to ???
Message-Id: <s0ehbtc490c4jtvevtihak5l16ego98p2n@4ax.com>

On Wed, 21 Mar 2001 09:08:32 -0500, "Francois Richard"
<richard@science.uottawa.ca> shed a beam of light on us:

>Can someone please point me in the right direction (FAQ, web resources,
>etc.)?
>
>I want to create a simple web page that allows guests to the web site to
>enter a userid and password, and store these with their names in a text
>or database file on our server.
>
>What is the best way to do this? Does it involve JavaScript alone, or a
>combination with other tools (CGI, Perl, Java, etc.)?
>
>I have looked for info on the internet, but so far this is proving to be
>a very frustrating experience... I would greatly appreciate any
>pointers/advice you may have.
>
>Cheers,
>_________________________________________________
>François Richard  -  Earth Sciences
>University of Ottawa (Canada)

If you're running unix, a .htaccess file should do the trick.

http://www.technotrade.com/htaccess/

-=Cornelis


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

Date: Wed, 21 Mar 2001 15:11:10 GMT
From: jtbell@presby.edu (Jon Bell)
Subject: Re: Q: usernames & passwords - how to ???
Message-Id: <GAJzIM.Cy2@presby.edu>

[posted to newsgroup with an e-mail copy to the questioner, since he 
apparently may be having problems with seeing posted responses]

In article <99ackv$b5u2@mercury.cc.uottawa.ca>,
Francois Richard <richard@science.uottawa.ca> wrote:
>
>I want to create a simple web page that allows guests to the web site to
>enter a userid and password, and store these with their names in a text
>or database file on our server.

You posted a question about this yesterday, and received several answers.  
Did you not see them?

-- 
Jon Bell <jtbell@presby.edu>                        Presbyterian College
Dept. of Physics and Computer Science        Clinton, South Carolina USA



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

Date: Wed, 21 Mar 2001 17:14:05 GMT
From: "R.J. Brown" <u7rjb@csc.liv.ac.uk>
Subject: question on string identification
Message-Id: <3AB8E15D.E32B7594@csc.liv.ac.uk>

I need to check the format of an input from a web page into a perl
script but don't know how.
It needs to be checked to ensure that there are no numbers or symbols in
the string, letters allowed only.
The solution I expect is really simple but I can't find the answer.

Thanks in advance.
Roger
u7rjb@csc.liv.ac.uk


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

Date: Wed, 21 Mar 2001 18:57:28 +0000
From: Dave Cross <dave@dave.org.uk>
Subject: Re: question on string identification
Message-Id: <e9uhbt4d14jp53ggo3m4g7p4m7so04dk5i@4ax.com>

On Wed, 21 Mar 2001 17:14:05 GMT, "R.J. Brown" <u7rjb@csc.liv.ac.uk>
wrote:

>I need to check the format of an input from a web page into a perl
>script but don't know how.
>It needs to be checked to ensure that there are no numbers or symbols in
>the string, letters allowed only.
>The solution I expect is really simple but I can't find the answer.

You'll need to use a regular expression to check the contents of your
string. I can't help you with the exact regular expression as it all
depends of what your exact rules are, but you can get a good
introduction to regexes in the perlre manual page which can with your
Perl distribution.

hth,

Dave...

-- 
<http://www.dave.org.uk>  SMS: sms@dave.org.uk
<http://www.manning.com/cross/>


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

Date: Wed, 21 Mar 2001 16:49:52 GMT
From: mnc@admin.u.nu (Miguel Cruz)
Subject: Re: Script for mail forwarding?
Message-Id: <QY4u6.2075$6Y3.731380@typhoon2.ba-dsg.net>

Randal L. Schwartz <merlyn@stonehenge.com> wrote:
> I'm told qmail also has an envelope-to translated as a header, but
> that scares me for spoofability if it's not matched-for properly.

Delivered-To:

Just make sure it precedes your local server's Received: header.

miguel


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

Date: Wed, 21 Mar 2001 17:01:19 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Script for mail forwarding?
Message-Id: <ehnhbtsl0eovpovs6mhrc31b8pkm3cdlai@4ax.com>

Miguel Cruz wrote:

>Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>> I'm told qmail also has an envelope-to translated as a header, but
>> that scares me for spoofability if it's not matched-for properly.
>
>Delivered-To:
>
>Just make sure it precedes your local server's Received: header.

I've just checked the headers in my mailbox. All the "Received:" headers
seem to take the form:

Received: from wolfbert.skynet.be (wolfbert.skynet.be [195.238.1.51])
	by solbert.skynet.be (8.9.3/jovi-pop-2.1) with ESMTP id QAA24712
	for <bart.lateur@skynet.be>; Mon, 29 May 2000 16:56:37 +0200
        (MET DST)

and that "for <.*>;" does look like the destination address to me. Or is
this the "envelope" that Randal was talking about?

-- 
	Bart.


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

Date: 21 Mar 2001 09:45:06 -0700
From: gls@byu.edu
Subject: Re: Script for mail forwarding?
Message-Id: <uofuvax65.fsf@SNOW.i-did-not-set--mail-host-address--so-shoot-me>

Rand Simberg <simberg@interglobal.org> writes:

> Is anyone aware of a canned script (either shell script or perl) for
> forwarding mail to aliased accounts?  (i.e., I have several domains on a
> server, and all of the mail goes to me by default, but I'd like specific
> domains or names@domains to get forwarded to some of my clients
> transparently.)  The script would just go through my mbox and filter on
> the recipient name, preserving all other headers, and then resend it to
> the aliased address.  It seems like a simple and common application, but
> a web search didn't turn anything up.

If you go to www.perl.com, select "reference", then select
"mail and USENET news", then scroll all the way to the bottom.
There is a script called "zfilter".  I've had success with this
in the past (though I don't think that it is being maintained
and I had to fix a couple of things to get some of the bells
and whistles to work).  

Basically you set up your .forward file to pipe all incoming 
mail through the script and set up a rules file to decide 
what to do with the mail (forward it, save it to your inbox,
delete it, save it to a different folder, etc).


Has anyone else in the group had experiance with zfilter?
either good or bad?

-- 
Greg Snow, PhD                Office: 223A TMCB
Department of Statistics      Phone:  (801) 378-7049
Brigham Young University      Dept.:  (801) 378-4505
Provo, UT  84602              email:  gls@byu.edu


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

Date: 21 Mar 2001 09:35:32 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Script for mail forwarding?
Message-Id: <m1lmpzhvob.fsf@halfdome.holdit.com>

>>>>> "gls" == gls  <gls@byu.edu> writes:

gls> Basically you set up your .forward file to pipe all incoming 
gls> mail through the script and set up a rules file to decide 
gls> what to do with the mail (forward it, save it to your inbox,
gls> delete it, save it to a different folder, etc).

By the time it hits your .forward, you've lost the envelope-to.
We're back to the 25% unparseable -- and thus dangerous -- posts.

-- 
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 Mar 2001 09:38:31 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Script for mail forwarding?
Message-Id: <m1elvrhvjc.fsf@halfdome.holdit.com>

>>>>> "Bart" == Bart Lateur <bart.lateur@skynet.be> writes:

Bart> I've just checked the headers in my mailbox. All the "Received:" headers
Bart> seem to take the form:

Bart> Received: from wolfbert.skynet.be (wolfbert.skynet.be [195.238.1.51])
Bart> 	by solbert.skynet.be (8.9.3/jovi-pop-2.1) with ESMTP id QAA24712
Bart> 	for <bart.lateur@skynet.be>; Mon, 29 May 2000 16:56:37 +0200
Bart>         (MET DST)

Bart> and that "for <.*>;" does look like the destination address to me. Or is
Bart> this the "envelope" that Randal was talking about?

There's one of the free domainhosters that I was playing with (I can't
recall which one) which set up ANYBODY@my-free-domain-thingy.com to be
forwarded to an address of my choosing.

Unfortunately, they seem to *skip* inserting the ANYBODY anywhere in
the headers... even when I looked at those "received:" lines.  There
was absolutely no way to distinguish ANYBODY=fred from ANYBODY=barney.
I even wrote them to complain... got back no response.

So just because you see "Received: ... for <...>" doesn't mean you
can get the envelope-to.

This is not a trivial problem, and is often mishandled.  That's what
we get for having an out-of-band "header". :)

And don't get me started about the mishandling of envelope-from as
well.

-- 
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: Wed, 21 Mar 2001 17:45:42 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Script for mail forwarding?
Message-Id: <slrn9bhq66.q57.abigail@tsathoggua.rlyeh.net>

Randal L. Schwartz (merlyn@stonehenge.com) wrote on MMDCCLIX September
MCMXCIII in <URL:news:m1elvrhvjc.fsf@halfdome.holdit.com>:
[] 
[] So just because you see "Received: ... for <...>" doesn't mean you
[] can get the envelope-to.

That's why I mentioned the Received line of your local MTA.

If you don't trust your local MTA, you better give up now.



Abigail
-- 
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'


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

Date: Wed, 21 Mar 2001 17:50:24 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Script for mail forwarding?
Message-Id: <slrn9bhqf0.q57.abigail@tsathoggua.rlyeh.net>

Randal L. Schwartz (merlyn@stonehenge.com) wrote on MMDCCLIX September
MCMXCIII in <URL:news:m1lmpzhvob.fsf@halfdome.holdit.com>:
== >>>>> "gls" == gls  <gls@byu.edu> writes:
== 
== gls> Basically you set up your .forward file to pipe all incoming 
== gls> mail through the script and set up a rules file to decide 
== gls> what to do with the mail (forward it, save it to your inbox,
== gls> delete it, save it to a different folder, etc).
== 
== By the time it hits your .forward, you've lost the envelope-to.

Says who? Maybe *you* lost your envelope-to, but I certainly don't.
By the time it hits my .forward, I know the envelope-to. Because if
it doesn't match that envelope-to, it won't hit that .forward.



Abigail
-- 
               split // => '"';
${"@_"} = "/"; split // => eval join "+" => 1 .. 7;
*{"@_"} = sub {foreach (sort keys %_)  {print "$_ $_{$_} "}};
%{"@_"} = %_ = (Just => another => Perl => Hacker); &{%{%_}};


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

Date: 21 Mar 2001 13:25:45 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Script for mail forwarding?
Message-Id: <m3y9tz3ro6.fsf@mumonkan.sunstarsys.com>

abigail@foad.org (Abigail) writes:

> Randal L. Schwartz (merlyn@stonehenge.com) wrote on MMDCCLIX September
> MCMXCIII in <URL:news:m1lmpzhvob.fsf@halfdome.holdit.com>:
> == >>>>> "gls" == gls  <gls@byu.edu> writes:
> == 
> == gls> Basically you set up your .forward file to pipe all incoming 
> == gls> mail through the script and set up a rules file to decide 
> == gls> what to do with the mail (forward it, save it to your inbox,
> == gls> delete it, save it to a different folder, etc).
> == 
> == By the time it hits your .forward, you've lost the envelope-to.
> 
> Says who? Maybe *you* lost your envelope-to, but I certainly don't.
> By the time it hits my .forward, I know the envelope-to. Because if
> it doesn't match that envelope-to, it won't hit that .forward.

For example:
  http://www.sendmail.org/faq/section3.html#3.29

Basically it's a trivial thing to add a header containing env-to info using
procmail installed as your local mailer (IIRC env-to is passed to
procmail via -d %u with the normal sendmail ruleset. By monkeying with 
sendmail.cf you can fix the -a flag to pass whatever you want to $1 in a 
procmailrc script.)

Also sendmail includes env-to in the for<> stanza of the Received
header, but that can be changed by remaking sendmail.cf with a 
different confRECEIVED_HEADER directive.

Yes, it's a FAQ, but in another ng. 

-- 
Joe Schaefer    "Don't go around saying the world owes you a living. The world
                            owes you nothing- it was here first."
                                               --Mark Twain


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

Date: Wed, 21 Mar 2001 10:53:36 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: small question - reading/writing data structures to/from file?
Message-Id: <Pine.A41.4.21.0103211010250.17380-100000@ginger.libs.uga.edu>

You mean "from/to file", right?  :-)

On Wed, 21 Mar 2001, Stan wrote:
> This can be the example structure:
> firstname (string)
> lastname (string)
> interests:
>    1 (yes/no)
>    2 (yes/no)
>    3 (yes/no)
>    4 (yes/no)
>    5 (yes/no)
> 
> for the interest part, its really five parts, each one is like a boolean (or
> int).
> I hope I"m not asking too much. I really am just learning this. I am coming
> from a c background.

At the risk of stepping a little (but not terribly) beyond 'basic', you
might look at the Data::Dumper module:


#!/usr/local/bin/perl
use warnings;
use strict;
use Data::Dumper;

my $record = {
  'firstname' => 'Brad',
  'lastname'  => 'Baxter',
  'interests' => [ 1, 0, 0, 1, 0 ],
  };

open OUT, ">file" or die "Can't open file: $!";
print OUT Data::Dumper->Dump( [$record], ['record'] );
close OUT;

open IN, "file" or die "Can't open file: $!";
my $new_record = eval { <IN> };
die $@ if $@;
close IN;

print `cat file`;

__END__

Output:

$record = {
            'lastname' => 'Baxter',
            'firstname' => 'Brad',
            'interests' => [
                             1,
                             0,
                             0,
                             1,
                             0
                           ]
          };




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

Date: Wed, 21 Mar 2001 11:35:07 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: small question - reading/writing data structures to/from file?
Message-Id: <Pine.A41.4.21.0103211132020.17380-100000@ginger.libs.uga.edu>

On Wed, 21 Mar 2001, Brad Baxter wrote:
> 
> open IN, "file" or die "Can't open file: $!";
> my $new_record = eval { <IN> };
> die $@ if $@;
> close IN;

I'm stupid and the above is wrong. :-(
This is a little better:  :-)


#!/usr/local/bin/perl
use warnings;
use strict;
use Data::Dumper;

my $record = {
  'firstname' => 'Brad',
  'lastname'  => 'Baxter',
  'interests' => [ 1, 0, 0, 1, 0 ],
  };

open OUT, ">file" or die "Can't open file: $!";
print OUT Data::Dumper->Dump( [$record], ['record'] );
close OUT;

my $new_record;
open IN, "file" or die "Can't open file: $!";
{
  local $/ = undef;
  $new_record = eval <IN>;
}
die $@ if $@;
close IN;

print Data::Dumper->Dump( [$new_record], ['new_record'] );




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

Date: Wed, 21 Mar 2001 17:03:39 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: small question - reading/writing data structures to/from file?
Message-Id: <kmnhbtopdovph290ll5o0oqa61m6o3fcj4@4ax.com>

Stan wrote:

>Can anyone please give me a little example of how to read a data structure
>from a file, and also write this structure to the file. I mean a basic
>example.
>
>This can be the example structure:
>firstname (string)
>lastname (string)
>interests:
>   1 (yes/no)
>   2 (yes/no)
>   3 (yes/no)
>   4 (yes/no)
>   5 (yes/no)

If you're talking a binray file structre: well, the format depends on
the compiler that the program saving this file, was compiled with. So I
won't go into any details. You'll have to examine a sample file
yourself.

But, in general: use unpack() to get at individual fields; pack() if
you're constructing such a record yourself.

-- 
	Bart.


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

Date: Wed, 21 Mar 2001 16:59:46 GMT
From: mnc@admin.u.nu (Miguel Cruz)
Subject: Re: substitution/pattern matching -- setting the position...
Message-Id: <665u6.2082$6Y3.734693@typhoon2.ba-dsg.net>

J.B. Moreno <planb@newsreaders.com> wrote:
>while ($chat =~ s/\n([hv][^ ]+ )(.+)\n\n\1/\n\1\2 /ig) {
>};

Couldn't you just do something far simpler:

  $chat =~ s/\s*\n+\s*/ /g;

miguel


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

Date: Wed, 21 Mar 2001 12:03:22 -0500
From: minorseventhSPAMBLOCK@earthlink.net (Jim Kroger)
Subject: Thanks for hash; how to read command line arguments?
Message-Id: <minorseventhSPAMBLOCK-2103011203230001@tritone.csbmb.princeton.edu>

Thanks to everyone who explained to me I need to be using a hash for my
needs rather than trying to kludge multiple variables into a single
variable name. Implementing the hash was a simple matter of a global
substitute and it works beautifully, now I understand them.


I have a different question: 

How can I read an argument given on the command line when executing a Perl
script? I know about @ARGV but according to "Learning Perl" (an exemplary
language book, btw) this only allows one to name files to be read from in
the script. I need to do something like:

Perl script is called do_fidap

foreach i(`ls *.df`)
foreach?  echo "doing $i"
foreach?  nohup do_fidap 84 $i &
foreach? end

So I need do_fidap to read two arguments, an integer and a filename, from
the command line, for internal use.

Each do_fidap process will take several hours to run. Nohup allows it to
continue even if my Mac (and my X windows program) crashes. Each process
will use a separate processor.  

THANKS!

Jim


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

Date: Wed, 21 Mar 2001 18:52:25 +0000
From: Dave Cross <dave@dave.org.uk>
Subject: Re: Thanks for hash; how to read command line arguments?
Message-Id: <70uhbtg0at49b8v1nh81drt3bujtgl7hai@4ax.com>

On Wed, 21 Mar 2001 12:03:22 -0500,
minorseventhSPAMBLOCK@earthlink.net (Jim Kroger) wrote:

>How can I read an argument given on the command line when executing a Perl
>script? I know about @ARGV but according to "Learning Perl" (an exemplary
>language book, btw) this only allows one to name files to be read from in
>the script. I need to do something like:

I think you're misunderstanding what Randal says :)

>Perl script is called do_fidap
>
>foreach i(`ls *.df`)
>foreach?  echo "doing $i"
>foreach?  nohup do_fidap 84 $i &
>foreach? end
>
>So I need do_fidap to read two arguments, an integer and a filename, from
>the command line, for internal use.

#!/usr/bin/perl -w

use strict;

my ($integer, $filename) = @ARGV;

Then do whatever you want with the values in $integer and $filename.

hth,

Dave...

-- 
<http://www.dave.org.uk>  SMS: sms@dave.org.uk
<http://www.manning.com/cross/>


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

Date: Wed, 21 Mar 2001 10:59:18 -0800
From: "Mike Stevens" <tick1@my-deja.com>
Subject: Threaded Perl on FreeBSD
Message-Id: <bS6u6.2451$E2.632886@newsrump.sjc.telocity.net>

Greetings,

I am trying to build a threaded Perl 5.6.0 on FreeBSD 4.2-RELEASE.  I ran
configure as:  sh Configure -des -Duserthreads -Duseithreads -Dcc=gcc.
make seemed to complete without errors.  However, make test fails on the
lib/posix test.  The README.threads file seems to apply to 5.005
threading style, so it does not seem to apply to my problem.  Does anyone
have any ideas what I need to do to get past this problem?  TIA,

-- 
Mike Stevens


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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


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