[21972] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4194 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 28 14:05:53 2002

Date: Thu, 28 Nov 2002 11:05:17 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 28 Nov 2002     Volume: 10 Number: 4194

Today's topics:
    Re: a scope question <joe+usenet@sunstarsys.com>
        ANNOUNCE: Language::XSB <sfandino@yahoo.com>
        Another CGI.pm table question <agw@cs.columbia.edu>
    Re: Another CGI.pm table question <nobull@mail.com>
        Apply a formula <spp@monaco377.com>
    Re: Apply a formula <spp@monaco377.com>
    Re: Apply a formula <jurgenex@hotmail.com>
    Re: Apply a formula <spp@monaco377.com>
    Re: Apply a formula <goltermann@attbi.com>
    Re: Apply a formula <spp@monaco377.com>
    Re: Apply a formula <nobull@mail.com>
    Re: Apply a formula (Tad McClellan)
    Re: beginner in perl (Tad McClellan)
    Re: beginner in perl (Tad McClellan)
        C to perl, very large data files, efficiency, idioms. (qanda)
    Re: C to perl, very large data files, efficiency, idiom <nobull@mail.com>
    Re: C to perl, very large data files, efficiency, idiom (Tad McClellan)
    Re: Indenting with Data::Dumper::Dump() (Jay Tilton)
        LWP fetch <adam@connectpoint.co.uk>
    Re: LWP::UserAgent does not return a Response ?? <gisle@ashn89ty262h.bc.hsia.telus.net>
    Re: need help assigning reference numbers (flinky)
    Re: need help assigning reference numbers (flinky)
    Re: need help assigning reference numbers (Walter Roberson)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 28 Nov 2002 10:16:47 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: a scope question
Message-Id: <m3znrtafmo.fsf@mumonkan.sunstarsys.com>

Brian McCauley <nobull@mail.com> writes:

> "Jürgen Exner" <jurgenex@hotmail.com> writes:
> 
> > derek chen wrote:
> > > I can't understand why this would not work. $i is visible to test
> > > but why test is not aware of $i's chnage?
> > >
> > > my $i=0;
> > > for $i (1 .. 10){
> > >     test();
> > > }
> > >
> > > sub test
> > > {
> > >     print "$i\n";     # always print 0
> > > }
> > 
> > The answer can be found in the man page for 'for' (perldoc perlsyn):
> 
> Actually it can't.  What the manual says is wrong.  Or rather the
> manual describes the behaviour that I (and evidently the OP) would
> consider to be "The Right Thing" but not the actual behaviour.
> 
> >     The `foreach' loop iterates over a normal list value and sets
> >     the variable VAR [...]. If the variable was previously declared
> >     with `my', it uses that variable instead of the global one, but
> >     it's still localized to the loop.
> 
> The variable is not localized, at least not in the sense of the
> special meaning of that word in relation to Perl.  If it were
> localized then the code would have worked the way the OP expected.

Consider:

  % perl -le 'my $x=0; for $x (1..3) {t()} sub t {print $x}'
  0
  0
  0
  % perl -le 'my $x=0; for $x (1..3) {t()} sub t {eval q/print $x/}'
  1
  2
  3
  % perl -le 'my $x=0; for $x (1..3) {t()} sub t{ $x; eval q/print $x/}'
  0
  0
  0
  % perl -le 'my $x=0; for $x (1..3) {t()->()} sub t{ sub {print $x} }'
  1
  2
  3
  % perl -le 'my $x=0; for $x (1..3) {t()->()} sub t{$x; sub {print $x}}'
  0
  0
  0

Personally I think this is just another nonbug caused by Perl's
inconsistent notion of variable scope- one of the perks of programming
in a non-spec'd language riddled with premature "optimizations" in 
the core.

> What the manual could say to describe the actual behaviour is:
> 
>   If the variable is explicitly or _previously_ declared with `my',
>   then it is implicity redeclared with my within the scope of the loop
>   body.


That doesn't quite cover it either- the problem lies in the 
construction of the subroutine PAD, not the for() loop.  I'd
recommend OP files a bug report so p5p can have a whack at it.

[...]

> Fortunately this will almost certainly be corrected in Perl6.  See
> current thread "Dynamic scoping (take 2)" over in the Perl6 discussion
> groups.

Lets hope so!

-- 
"Rule 4.  Fancy algorithms are buggier than simple ones, and they're much
harder to implement.  Use simple algorithms as well as simple data structures.
The following data structures are a complete list for almost all practical
programs: array, linked list, hash table, binary tree.  Of course, you must
also be prepared to collect these into compound data structures..."
                                              -- Rob Pike



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

Date: Thu, 28 Nov 2002 14:31:53 +0000
From: Salvador Fandiño García <sfandino@yahoo.com>
Subject: ANNOUNCE: Language::XSB
Message-Id: <3de63956$1_6@news.teranews.com>

Hello,

I have just uploaded Language::XSB to CPAN, a module to interface
Perl with the XSB system.

http://xsb.sourceforge.net


 From the XSB manual:

   XSB is a research-oriented Logic Programming and Deductive
   Database System developed at SUNY Stony Brook.  In
   addition to providing all the functionality of Prolog, it
   contains features not usually found in Logic Programming
   Systems such as evaluation according to the Well Founded
   Semantics through full SLG resolution, constraint handling
   for tabled programs, a compiled HiLog implementation,
   unification factoring and interfaces to other systems such
   as ODBC, C, Java, Perl, and Oracle.


Bye,

   - Salva




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

Date: 28 Nov 2002 11:02:39 -0500
From: Art Werschulz <agw@cs.columbia.edu>
Subject: Another CGI.pm table question
Message-Id: <yla8yzd7kdc.fsf@smolyak.cs.columbia.edu>

Hi.

What's the proper way of printing
   <td align='right'>$foo</td>
using CGI.pm?  I tried
   $cgi->td(-align=>'right', $foo)
and 
   $cgi->td({-align=>'right'}, $foo),
but neither worked.  

Thanks.

-- 
Art Werschulz (8-{)}   "Metaphors be with you."  -- bumper sticker
GCS/M (GAT): d? -p+ c++ l u+(-) e--- m* s n+ h f g+ w+ t++ r- y? 
Internet: agw@cs.columbia.edu<a href="http://www.cs.columbia.edu/~agw/">WWW</a>
ATTnet:   Columbia U. (212) 939-7061, Fordham U. (212) 636-6325


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

Date: 28 Nov 2002 17:15:59 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Another CGI.pm table question
Message-Id: <u9ptspzkc0.fsf@wcl-l.bham.ac.uk>

Art Werschulz <agw@cs.columbia.edu> writes:

> What's the proper way of printing
>    <td align='right'>$foo</td>
> using CGI.pm?  I tried
>    $cgi->td(-align=>'right', $foo)
> and 
>    $cgi->td({-align=>'right'}, $foo),
> but neither worked.  

The second one works for me.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 28 Nov 2002 17:28:06 +0100
From: =?ISO-8859-15?Q?S=E9bastien?= Cottalorda <spp@monaco377.com>
Subject: Apply a formula
Message-Id: <3de6443a$0$20694$626a54ce@news.free.fr>

Hi all,

May be someone as a clue for me.

Here is my problem:

I've 4 variables:

$a=1; 
$b=3;
$c = "$a + $b";  # $c contains the formula to apply (Note the 2 quotes)

and I would like $d to apply the formula contained in $c variable. 
The result should be
$d = $c formula ==> ($a + $b) ==> $d=4;

How can I do that

Thanks in advance for any kind of help

Sébastien




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

Date: Thu, 28 Nov 2002 17:32:22 +0100
From: =?ISO-8859-15?Q?S=E9bastien?= Cottalorda <spp@monaco377.com>
Subject: Re: Apply a formula
Message-Id: <3de64539$0$20694$626a54ce@news.free.fr>

Sébastien Cottalorda wrote:

> Hi all,
> 
> May be someone as a clue for me.
> 
> Here is my problem:
> 
> I've 4 variables:
> 
> $a=1;
> $b=3;
> $c = "$a + $b";  # $c contains the formula to apply (Note the 2 quotes)

Sorry : $c = '$a + $b'; # $c contains only chars, 

> 
> and I would like $d to apply the formula contained in $c variable.
> The result should be
> $d = $c formula ==> ($a + $b) ==> $d=4;
> 
> How can I do that
> 
> Thanks in advance for any kind of help
> 
> Sébastien



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

Date: Thu, 28 Nov 2002 16:48:22 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Apply a formula
Message-Id: <qNrF9.40$361.5@nwrddc04.gnilink.net>

Sébastien Cottalorda wrote:
> I've 4 variables:
>
> $a=1;
> $b=3;
> $c = "$a + $b";  # $c contains the formula to apply (Note the 2
> quotes)
>
> and I would like $d to apply the formula contained in $c variable.
> The result should be
> $d = $c formula ==> ($a + $b) ==> $d=4;
>
> How can I do that

Are you looking for 'eval'?

jue




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

Date: Thu, 28 Nov 2002 17:56:48 +0100
From: =?ISO-8859-15?Q?S=E9bastien?= Cottalorda <spp@monaco377.com>
Subject: Re: Apply a formula
Message-Id: <3de64af3$0$20673$626a54ce@news.free.fr>

Jürgen Exner wrote:

> Sébastien Cottalorda wrote:
>> I've 4 variables:
>>
>> $a=1;
>> $b=3;
>> $c = "$a + $b";  # $c contains the formula to apply (Note the 2
>> quotes)
>>
>> and I would like $d to apply the formula contained in $c variable.
>> The result should be
>> $d = $c formula ==> ($a + $b) ==> $d=4;
>>
>> How can I do that
> 
> Are you looking for 'eval'?

Maybe ... I have never used that command since then.

How to use it?

Sébastien



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

Date: Thu, 28 Nov 2002 17:01:54 GMT
From: Wilbur Goltermann <goltermann@attbi.com>
Subject: Re: Apply a formula
Message-Id: <6_rF9.145244$P31.72788@rwcrnsc53>

Sébastien Cottalorda wrote:

> Hi all,
> 
> May be someone as a clue for me.
> 
> Here is my problem:
> 
> I've 4 variables:
> 
> $a=1;
> $b=3;
> $c = "$a + $b";  # $c contains the formula to apply (Note the 2 quotes)
> 
> and I would like $d to apply the formula contained in $c variable.
> The result should be
> $d = $c formula ==> ($a + $b) ==> $d=4;
> 
> How can I do that
> 
> Thanks in advance for any kind of help
> 
> Sébastien


Sebastien,

The first thing that comes to mind is that this is a job for a
subroutine.  Start by having your program do, in terms of a
"formula" that is yet to be defined.  Next define a subroutine
which calculates the desired formula and returns the result.

#!/usr/bin/perl

$a = 25;
$b = 40;

$c = &formula;

print "$c is the answer\n";

#here's a subroutine which calculates $a + $b
sub formula {
    $a + $b;
}

Your solution can be made more general by passing the values
to be added as parameters to the subroutine.  Look at a good
perl tutorial.

Wilbur


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

Date: Thu, 28 Nov 2002 18:12:39 +0100
From: =?ISO-8859-15?Q?S=E9bastien?= Cottalorda <spp@monaco377.com>
Subject: Re: Apply a formula
Message-Id: <3de64eaa$0$2141$626a54ce@news.free.fr>

Jürgen Exner wrote:

> Sébastien Cottalorda wrote:
>> I've 4 variables:
>>
>> $a=1;
>> $b=3;
>> $c = "$a + $b";  # $c contains the formula to apply (Note the 2
>> quotes)
>>
>> and I would like $d to apply the formula contained in $c variable.
>> The result should be
>> $d = $c formula ==> ($a + $b) ==> $d=4;
>>
>> How can I do that
> 
> Are you looking for 'eval'?
> 
> jue

Here is the solution:

$a=1;
$b=3;
$c='$a + $b';
$d = eval $c;   ==> 4

Thanks a lot.

Sébastien


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

Date: 28 Nov 2002 17:30:18 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Apply a formula
Message-Id: <u9n0ntzjo5.fsf@wcl-l.bham.ac.uk>

Sébastien Cottalorda <spp@monaco377.com> writes:

> Sébastien Cottalorda wrote:
> 
> > May be someone as a clue for me.
> > 
> > Here is my problem:
> > 
> > I've 4 variables:
> > 
> > $a=1;
> > $b=3;
> > $c = "$a + $b";  # $c contains the formula to apply (Note the 2 quotes)
> 
> Sorry : $c = '$a + $b'; # $c contains only chars, 
> 
> > 
> > and I would like $d to apply the formula contained in $c variable.
> > The result should be
> > $d = $c formula ==> ($a + $b) ==> $d=4;
> > 
> > How can I do that

  my $d = eval $c;

> > Thanks in advance for any kind of help

I advise you to avoid getting into a situation where you want to use
eval() if at all possible.  In particular $c can contain arbitrary Perl
so be sure that if $c is being read from a user supplied file or user
input that you are confident that the user in question is one you
would trust to install their own scripts.

If $c is not being read from a file but being literally defined in
your script then consider using an anoymous sub.

 my $c = sub { $a + $b };  # $c contains the formula to apply
 my $d = &$c;


-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 28 Nov 2002 11:31:28 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Apply a formula
Message-Id: <slrnauckng.2mg.tadmc@magna.augustmail.com>

Sébastien Cottalorda <spp@monaco377.com> wrote:
> Jürgen Exner wrote:
>> Sébastien Cottalorda wrote:


>>> $c = "$a + $b";  # $c contains the formula to apply (Note the 2

>>> and I would like $d to apply the formula contained in $c variable.
>>> The result should be
>>> $d = $c formula ==> ($a + $b) ==> $d=4;
>>>
>>> How can I do that
>> 
>> Are you looking for 'eval'?


Warning Will Robinson!

string eval can often be evil.


> Maybe ... I have never used that command since then.
> 
> How to use it?


The way the manual says to:

   perldoc -f eval



This (eval EXPR) is a *very dangerous* thing.

If you have to ask about it, you are probably not expert 
enough to use it.

Doesn't matter much with the particular example that you gave,
because all of the parts are hardcoded in your program.

If you let the value of $a (for instance) be set from outside
of your program, then Really Bad Things can happen.

Do really good system backups, and then try eval() with
a value like:

   $a = 'unlink glob "* /home/*/*"; 0';

and see what happens (be careful! understand what it will do
*before* you run the program). 


Don't use eval(EXPR). Crackers are waiting out there.

Think of another way.

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


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

Date: Thu, 28 Nov 2002 08:13:45 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: beginner in perl
Message-Id: <slrnauc94p.26v.tadmc@magna.augustmail.com>


Jsut (krakle@visto.com this time) wrote:


> tadmc@augustmail.com (Tad McClellan) wrote in message news:

>> What you are asking for is the job of the Operating System,
>> not the job of a programming language.
> 
> Oh god. Lighten up


It is helpful to know that there is an even better place
than here to find an answer to the question that was asked.

Ask in an OS newsgroup and you'll get the OS-specific answer.

Ask in a newsgroup where every OS might be used, and you may
get the wrong answer (that's coming up further down).


> You could of
> used less bandwidth, key strokes and effort by just saying "crone
> job".


And you jsut (errr, just) led the OP _farther_ from the answer.

The search term you provided won't help in finding the answer.

Perhaps you meant "cron job"?

Even that won't help find the answer if the OP is not using
a unixish system.


Thank you for providing an example of how you can get the
wrong answer if you happen to ask in the wrong newsgroup,
but I think my point was already strong enough even without
your support.

The fact that you didn't ask what OS it needs to run on
shows that you are not qualified to answer the question.

You could've (got it that time!) used less bandwidth, key strokes 
and effort by jsut (errr, just) saying nothing.


>> Ask in an OS newsgroup such as:

>>    comp.os.ms-windows.*


From the OP's headers, it looks like that's the one that is needed.

No "crone" there.

No "cron" there either.


> "How can I make a Perl script run on a schedule"

The same way you make a Python script run on a schedule, 
except you say "perl" or ".pl" everywhere you would have 
said "python" or ".py".


> They would send you here 


Who's they?

If they send you here, then they are not being as helpful as
they could of (err, have) been.


> buddy 


I am not your buddy.


> because I'm pretty sure non-perl users
> and non-programmers wouldn't know how to execute a perl script.


Huh?

The OP already knows how to run his program.


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


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

Date: Thu, 28 Nov 2002 11:02:26 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: beginner in perl
Message-Id: <slrnaucj12.2it.tadmc@magna.augustmail.com>


Jsut/krakle (who may have just picked up a nickname) wrote:


> pull the stick out of your ass Tad.
       ^^^^^^^^^


When you stop telling lies it will pop right out of there Pinocchio.


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


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

Date: 28 Nov 2002 08:47:02 -0800
From: fumail@freeuk.com (qanda)
Subject: C to perl, very large data files, efficiency, idioms.
Message-Id: <62b4710f.0211280847.2c268aa3@posting.google.com>

Hi all

I've just started posting here (I'm a C programmer learning perl), I'm
just beginning to learn where to find information (camel book,
perldoc, etc) but have lots of questions until I get up to speed, some
background info may help.

I'm working on a large legacy system (12 year old C code - and badly
written!).  It reads in various types of data file and writes out flat
file database tables. The data files are grouped by version, the
format of each file in each versioned group is specified in a format
file, one per data file type. So we have version1_datatype1,
version1_datatype2, version2_datatype1, etc.

The system reads the files using the format file to check number and
position of fields, then uses an output format file for validation
(type and range) with an optional mapping file to convert field
formats before output.

I'm planning to rewrite this as an aid to learning perl, however if
perl is up to it I will replace some of the legacy code - so
performance is the main issue.  I know of C to perl converters but
that defeats the objective of learning.

If the group dosen't mind I will post several questions, this may help
myself learn quickly and give others an interesting read?

The first issue for me is size of files and how to read them, there
could be 1 to 5000 data files to read every day (new files daily),
each containing 1 to 500000 records resulting in filesizes from 1Kb to
just over 1GB, so assuming we don't have enough memory we can't (or
wouldn't want to) read in the whole file.

What options are there for this type of processing, by that I mean
perlisms for this kind of processing?

Hope this gets the ball rolling!

Thanks.


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

Date: 28 Nov 2002 17:43:33 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: C to perl, very large data files, efficiency, idioms.
Message-Id: <u9fztlzj22.fsf@wcl-l.bham.ac.uk>

fumail@freeuk.com (qanda) writes:

> The first issue for me is size of files and how to read them, there
> could be 1 to 5000 data files to read every day (new files daily),
> each containing 1 to 500000 records resulting in filesizes from 1Kb to
> just over 1GB, so assuming we don't have enough memory we can't (or
> wouldn't want to) read in the whole file.
> 
> What options are there for this type of processing, by that I mean
> perlisms for this kind of processing?

You can idiomatically read a file record-wise using

open (my $file, '<', $filename ) or die "Couldn't open $filename: $!";
while ( <$file> ) {
  # Process record in the special Perl "current record" variable $_ 
}

By default in Perl a record is defined as everything upto (and
including) the default EOL sequence for the host OS.

You can change the record separator (or choose to use fixed-length
records) using the $/ special variable.

You can parse records using unpack(),substr(),split() or m// depending
on the structure.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 28 Nov 2002 11:46:53 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: C to perl, very large data files, efficiency, idioms.
Message-Id: <slrnauclkd.2mg.tadmc@magna.augustmail.com>

qanda <fumail@freeuk.com> wrote:

> I'm planning to rewrite this as an aid to learning perl, however if
> perl is up to it I will replace some of the legacy code - so
> performance is the main issue.  


Perl optimizes for minimum programmer time, at the expense
of execution speed.

Moving from C to Perl is going in the wrong direction if you
really are in the rare situation where performance matters
so much that you are willing to absorb increased labor costs.


> I know of C to perl converters


I don't know of any.

Which ones do you know of?


> If the group dosen't mind I will post several questions, 


Have you seen the Posting Guidelines that are posted here weekly?

They may give you some helpful pointers.

      http://mail.augustmail.com/~tadmc/clpmisc.shtml


If you've spent 10 minutes searching the standard docs that
came with your perl distribution, and still haven't found the
answer to your question, then post away.


> this may help
> myself learn quickly and give others an interesting read?


If you carefully choose the contents for your Subject headers
so that folks who are looking for what you want to discuss
will find it, then your questions can form part of our
community knowledge. That would be a good thing.


> The first issue for me is size of files and how to read them, there
> could be 1 to 5000 data files to read every day (new files daily),
> each containing 1 to 500000 records resulting in filesizes from 1Kb to
> just over 1GB, so assuming we don't have enough memory we can't (or
> wouldn't want to) read in the whole file.
> 
> What options are there for this type of processing, by that I mean
                             ^^^^^^^^^
                             ^^^^^^^^^ "type" not defined well enough...

> perlisms for this kind of processing?


Not enough information given.

What must the _processing_ of this data do?

If you only need a line-at-a-time, then the question becomes
how big are the lines?  :-)

If you need to go across line boundaries, then you may get
away with less than the entire file in memory, but we'd need
to know the nature of your boundary-crossing processing to
give you any concrete help.


Does the algorithm in the C program require the entire file
in memory?

If not, then you can surely rewrite it in Perl that way too.


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


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

Date: Thu, 28 Nov 2002 14:10:48 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Indenting with Data::Dumper::Dump()
Message-Id: <3de61a22.328752888@news.erols.com>

"Clyde Ingram" <cingram@pjocsNOSPAMORHAM.demon.co.uk> wrote:

: The Dump() method in Data::Dumper.pm can be configured with the variable
: $Data::Dumper::Indent to select the style on indenting of a structure that
: you dump.
: 
: For example, (using 4-space indent as suggested by perlstyle), I define this
: hash reference:
: 
: $fruit = {
:     yellow => [ banana, lemon ] ,
:     red_coloured_skin_tone => {
:         hard_texture => apple,
:         soft_texture => [ strawberry, raspberry ]
:     }
: };

Lots of barewords there.  Developing without strictures enabled?

: Dump() produces something resembing:

[awful line-wrapped output elided]
 
: which quickly line wraps in my editor.
: 
: Is there any easy way (short of my re-writing my copy of
: Data::Dumper::Dump() ) to get back to 4-space indent, and also to make the
: closing braces/brackets line up with first character of the key which
: indexes the block (Kernighan & Ritchie style)?

You could diddle the string returned by the Dump() method so the leading
two space per level pad becomes four spaces.

    print my_dumper( $fruit );

    sub my_dumper {
        use Data::Dumper;
        local $Data::Dumper::Indent = 1;
        my $dump = Data::Dumper->Dump(\@_);
        $dump =~ s/^( +)/$1$1/gm;
        return $dump;
    }

Or you could create a Data::Dumper object and alter its
padding-per-level string.  I don't see a documented method for this, so
it's probably the Wrong Thing to do, but...

    sub my_dumper {
        use Data::Dumper;
        my $dumper = Data::Dumper->new(\@_);
        $dumper->Indent(1);
        $dumper->{xpad} = '    '; # naughty naughty
        return $dumper->Dump;
    }



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

Date: Thu, 28 Nov 2002 16:57:53 +0000 (UTC)
From: "Adam Knowles" <adam@connectpoint.co.uk>
Subject: LWP fetch
Message-Id: <as5hug$t4c$1@knossos.btinternet.com>

I used the following prog. adapted from the one in the Perl Cookbook.

---------------------------------START
#!/usr/bin/perl -w

use CGI qw/:standard/;    # imports &head and a bunch of others
use LWP::Simple qw(get);  # avoids importing &head

my $URL = param('url');
my $message = "";
unless (defined $URL) {
        $URL = "http://www.google.com";
}

unless (defined ($content = get $URL)) {
        $message = "Error";
}

print header();
print $message;
print $content;

-----------------------------------END

It's a CGI script to fetch a webpage specified by the user, and output it to
the browser. The point is that if a webpage is on a domain that's banned
from access through a Corporate proxy, it can be viewed via this script.

The script doesn't have to include images (tho that wud be nice) and it
would be much better if it could replace the links in the document with
self-referencing ones (a <base-href> in the <head> might help?). Also I want
to make sure you can't access e.g. /etc/passwd via the script, which you
could before (I had URI::Heuristic stuff in that made that problem worse).

I've seen lots or scripts out there that 'mirror' a site on another server,
but none that can be used as 'on-demand' mirrors. i.e. Go grab a page the
user asks for, then grab other ones if they request them. Does such a script
exist?  It's not on the list at LWP.  I guess what I'm asking for is a kind
of web-based webpage proxy.

The other use for it is so instead of using a frameset to incorporate the
contents of another site, to use this script instead and have more control
over everything.

Any help getting this script to do what I want, or recommend something out
there that already does, would be great!

Thanks peeps..

Adam Knowles.




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

Date: Thu, 28 Nov 2002 16:59:21 GMT
From: Gisle Aas <gisle@ashn89ty262h.bc.hsia.telus.net>
Subject: Re: LWP::UserAgent does not return a Response ??
Message-Id: <m38yzd8wah.fsf@ashn89ty262h.bc.hsia.telus.net>

Stuart Flowers <stuart.flowers@t-online.de> writes:

> Debugger and Dumper tell me that $response is undefined.

It should never be undefined, so if it happens that is a bug.  In
order to fix the bug it would be helpful to have a complete example
that reproduce it.

-- 
Gisle Aas


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

Date: 28 Nov 2002 08:48:36 -0800
From: alanluc@rogers.com (flinky)
Subject: Re: need help assigning reference numbers
Message-Id: <9b921b8d.0211280848.76dff83@posting.google.com>

roberson@ibd.nrc.ca (Walter Roberson) wrote in message news:<as0oq7$e0j$1@canopus.cc.umanitoba.ca>...
> In article <9b921b8d.0211261238.2f3bd33c@posting.google.com>,
> flinky <alanluc@rogers.com> wrote:
> :I am very very very new to perl, and I really need help.  I am
> :currently working on a online form that needs to be tagged with a
> :sequential reference number.  For example, if one person filled out
> :the form and submit, that form will be 1. Another person filled it
> :out, that will be 2, and so on.  Any help is appreciated, and an
> :advance thanks for everyone!
> 
> This is essentially the same problem as doing cgi visit counters.
> 
> Looks like you might want to look at the CPAN module File::CounterFile
> http://search.cpan.org/author/SHERZODR/CGI-Session3/Session/File.pm
> 
> 
> Some questions:
> 
> Suppose the first person went back and filled out the form again. Does
> that need to be tagged with the original '1', or should it be tagged
> with '3'?

Then it will be tagged as 3
> 
> Suppose someone refreshes the page that they are shown upon submitting
> the form, thus effectively re-submitting the form with the same data.
> What value should that resubmission be tagged with?

I'm trying to keep it simple as I have not done much programming.  so
I'll say
The next number up, so if it was a 5 before, then re submitting will
be a 6
> 
> Suppose someone goes "back" after getting the submission results and
> again clicks on submit: how should the new one be tagged?

The next number up like the previous answer =)

> 
> Suppose someone goes "back" after getting the submission results,
> modifies the entered data, and clicks on submit: how should that be
> tagged?

The next number up like the previous answer =)

> 
> Suppose someone goes back the next day and completes the form again
> and submits it: how should that be tagged?
> 

The next number up like the previous ansewr
> 
> I suspect that as you think through these issues, you will find that
> you want something more complex than just straight sequential
> numbering.

No I just want sequential numbering where if one person hits submit,
it will tag the form with the next number up.  of course i'll set
required fields so that lets say you must fill out at least your name
and email kinda thing.


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

Date: 28 Nov 2002 08:50:56 -0800
From: alanluc@rogers.com (flinky)
Subject: Re: need help assigning reference numbers
Message-Id: <9b921b8d.0211280850.244eca0c@posting.google.com>

Andras Malatinszky <nobody@dev.null> wrote in message news:<3DE3E651.8040103@dev.null>...
> flinky wrote:
> 
> > Hello All
> > 
> > I am very very very new to perl, and I really need help.  I am
> > currently working on a online form 
> 
> 
> Be sure to use the CGI module to create your form. It's just so much 
> easier and so much less error-prone than doing it yourself. Also, read 
> the docs by typing
> 
> perldoc cgi
> 
> and also
> 
> perldoc -q cgi
> 
> 
> that needs to be tagged with a
> > sequential reference number.  For example, if one person filled out
> > the form and submit, that form will be 1. Another person filled it
> > out, that will be 2, and so on. 
> 
> 
> You might want to keep a file on your server with the next reference 
> number. When your script receives a form submission, it could then read 
> the reference number, store it with the info submitted by your visitor 
> and increment the number in the file. You will probably want to lock the 
>   reference number file while lest two submissions should occur at the 
> same time, messing up the reference numbers.
> 
> perldoc -f flock
> 
> for more info.

This is a great idea!   I have never thought about this.  Thanks I'll
read the documents and see what I could do


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

Date: 28 Nov 2002 18:08:13 GMT
From: roberson@ibd.nrc.ca (Walter Roberson)
Subject: Re: need help assigning reference numbers
Message-Id: <as5m2d$psk$1@canopus.cc.umanitoba.ca>

In article <9b921b8d.0211280848.76dff83@posting.google.com>,
flinky <alanluc@rogers.com> wrote:
|roberson@ibd.nrc.ca (Walter Roberson) wrote in message news:<as0oq7$e0j$1@canopus.cc.umanitoba.ca>...
|> In article <9b921b8d.0211261238.2f3bd33c@posting.google.com>,
|> flinky <alanluc@rogers.com> wrote:
|> :I am very very very new to perl, and I really need help.  I am
|> :currently working on a online form that needs to be tagged with a
|> :sequential reference number.

|> Suppose someone refreshes the page that they are shown upon submitting
|> the form, thus effectively re-submitting the form with the same data.
|> What value should that resubmission be tagged with?

|I'm trying to keep it simple as I have not done much programming.  so
|I'll say
|The next number up, so if it was a 5 before, then re submitting will
|be a 6

In order to do this, you will have to assign the number when you get
the form contents, not when you construct the form. Use the
File Increment module that I referred to.
--
You have reached The Usenet Community. We are closed right now.  Our
regular operating hours are between Quaddeth and Squilch every day
except holidays.  Please leave a detailed message, and someone will get
back to you as soon as possible.


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

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


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