[19572] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1767 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 18 14:05:33 2001

Date: Tue, 18 Sep 2001 11:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1000836309-v10-i1767@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 18 Sep 2001     Volume: 10 Number: 1767

Today's topics:
        convert time string to date format <ppi_at_searchy@dot.net>
    Re: convert time string to date format <Thomas@Baetzler.de>
    Re: convert time string to date format <clay@panix.com>
    Re: example for rewinddir <bart.lateur@skynet.be>
    Re: HELP!  Having Trouble concatenating or joining and  <jeff@vpservices.com>
    Re: HELP!  Having Trouble concatenating or joining and  (codeslayer)
    Re: HELP!  Having Trouble concatenating or joining and  <clay@panix.com>
        html 2 xml <dave@nospam.stratumonline.com.del>
    Re: HTML-parsing prob - need regexpression help <Thomas@Baetzler.de>
    Re: local() breaks with imported vars (Exporter bug?) <mjcarman@home.com>
        MAJOR problems with Storable, and pipe. Help Please. (Stan Brown)
    Re: Need help with this regex problem: <bart.lateur@skynet.be>
        newbie question - why it gives filehandle error? <hwc33@hotmail.com>
    Re: newbie question - why it gives filehandle error? <dtweed@acm.org>
    Re: newbie question - why it gives filehandle error? <ren@tivoli.com>
        object to string and back to object..... (Weston Cann)
    Re: object to string and back to object..... (Randal L. Schwartz)
    Re: object to string and back to object..... (Weston Cann)
    Re: Objects and Sockets (Del)
        Open Multiple URL's or Web Pages with Perl or JPG or gi (codeslayer)
    Re: Perl (slurping) is TOO much fun <nospam-abuse@ilyaz.org>
    Re: Persistence in Perl (Randal L. Schwartz)
    Re: Persistence in Perl <bart.lateur@skynet.be>
    Re: Persistence in Perl <mmanso@prodigio.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 18 Sep 2001 13:35:22 GMT
From: Frank de Bot <ppi_at_searchy@dot.net>
Subject: convert time string to date format
Message-Id: <u4Ip7.28671$J7.435819@dbsch1.home.nl>

Hi,

I want to convert string like these: "Mon Sep 17 16:49:46 2001" to the 
number of seconds since 1 jan 1970. How can I do this? I want to do this, 
because one of the applications I run will only log time formats like that.


Thanks in  Advanced,

Frank de Bot!


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

Date: Tue, 18 Sep 2001 16:46:47 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: convert time string to date format
Message-Id: <74neqtknpfaqmdh46sfuqfjcebkhb1039f@4ax.com>

On Tue, 18 Sep 2001, Frank de Bot <ppi_at_searchy@dot.net> wrote:
>I want to convert string like these: "Mon Sep 17 16:49:46 2001" to the 
>number of seconds since 1 jan 1970. How can I do this? I want to do this, 
>because one of the applications I run will only log time formats like that.

Use the Time::Local module. If you time spec is GMT, replace timelocal
with timegm.

#!/usr/bin/perl -w

use strict;
use Time::Local;

my %month = (
  'Jan' => 0, 'Feb' => 1, 'Mar' => 3,
  'Apr' => 0, 'May' => 1, 'Jun' => 3,
  'Jul' => 0, 'Aug' => 1, 'Sep' => 3,
  'Oct' => 0, 'Nov' => 1, 'Dec' => 11 );

my $datetime = "Mon Sep 17 16:49:46 2001";

my( undef, $mm, $dd, $h, $m, $s, $yy ) =
  split /[ :]+/, $datetime;

$mm = $month{$mm};

my $ticks = timelocal($s,$m,$h,$dd,$mm,$yy);

print "$datetime is $ticks seconds after 0:00:00 on 1. 1. 1970\n";

HTH,
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


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

Date: 18 Sep 2001 14:55:10 GMT
From: Clay Irving <clay@panix.com>
Subject: Re: convert time string to date format
Message-Id: <slrn9qeo4d.dn7.clay@panix1.panix.com>

In article <u4Ip7.28671$J7.435819@dbsch1.home.nl>, Frank de Bot wrote:

> I want to convert string like these: "Mon Sep 17 16:49:46 2001" to the 
> number of seconds since 1 jan 1970. How can I do this? I want to do this, 
> because one of the applications I run will only log time formats like that.

One way:

  #!/usr/local/bin/perl
  
  use Date::Manip;
  
  $string = "Mon Sep 17 16:49:46 2001";
  
  $sec = UnixDate(ParseDate($string),"%s");
  print "$sec\n";

Result:

  1000770586

-- 
Clay Irving <clay@panix.com>
My mother taught me about STAMINA:
"You'll sit there 'til all that spinach is finished."


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

Date: Tue, 18 Sep 2001 14:02:25 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: example for rewinddir
Message-Id: <pskeqtsp978b9u1eijhhfajdp9ccfcu1vj@4ax.com>

Anno Siegel wrote:

>According to Joachim Ziegler <ziegler@algorilla.de>:
>> can someone give me a good example
>> for a situation, in which "rewinddir" is useful?
>> 
>> i don't see any!
>
>You can't think of a situation where it would be useful to read
>a directory twice?

I don't see a reason for stopping and restarting halfway through. If you
want to read it twice, it's just as easy to opendir() again.

(Unfortunately, and opposed to close() for a file, there is no implicit
closedir().)

-- 
	Bart.


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

Date: Tue, 18 Sep 2001 07:53:20 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: HELP!  Having Trouble concatenating or joining and making or   building  a url with ActivePerl and the '.' operator.
Message-Id: <3BA75FE0.AE577ECE@vpservices.com>

codeslayer wrote:
> 

> $count = 06;

If you want the final to be a zero followed by a six, then you need to
quote this.  If it's a number then 06 will be reduced to the number 6.

Given that change, on windows the first and third worked and these two
failed because:

> $url_t2 = "$rtpath/$picrt$count..$ext";

Puts in two periods because you told it to.  A period inside a quote is
just a period, not a concatenator.

> $url_t4 = "$rtpath/$picrt$count.\$ext";

Prints ".$ext" instead of ".html" because a backslash inside quotes
ecapes the next character, i.e. the dollar sign becomes just a dollar
sign, not a variable indicator.


> http://www.news.com/pageq_6.html

Right, that's what it looks like if you use $count = 06 instead of
$count = '06'.  And BTW, If $count = '06' (with the quote marks) then
$count++ becomes '07'.  The thing I am not clear about is why this
worked for you on AIX without the quotes around '06'.

-- 
Jeff



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

Date: 18 Sep 2001 06:12:10 -0700
From: weedmonster_99@yahoo.com (codeslayer)
Subject: Re: HELP!  Having Trouble concatenating or joining and making or  building  a url with ActivePerl and the '.' operator.
Message-Id: <4b459565.0109180512.a5df23d@posting.google.com>

Jeff Zucker <jeff@vpservices.com> wrote in message news:<3BA69467.F482E75E@vpservices.com>...

> You've told us that you put apples, flour, and sugar in the pie pan, but
> not what order you put them in or what temperature you cooked it at. 
> The ingredients are correct but how do we know why the pie came out
> wrong?  Show us the code that produced the false results or we'll have
> no way to know why it doesn't do what you expect.

OOPS! --> Sorry,  I did get a little ahead of myself.  Here is the
code that I have tried:

=================================

#!/usr/bin/perl -w
#

################################################
# DEFINE TEST VARIABLES:
################################################
#
$rtpath = "http://www.news.com";

$picrt = "pageq_";

$count = 06;	#(or whatever the count is at the time,)

$ext = "html";


################################################
# VARIOUS ATTEMPTS TO CREATE THE URL:
################################################

$url_t1 = "$rtpath/$picrt$count.$ext";

$url_t2 = "$rtpath/$picrt$count..$ext";

$url_t3 = "$rtpath/" . "$picrt" . "$count" . ".$ext";

$url_t4 = "$rtpath/$picrt$count.\$ext";


################################################
# PRINT URL TEST OUTPUT:
################################################
#
# NOTE:		These worked on my AIX box at
#		work, but do not work on my
#		PC for some reason.
#

print $url_t1;
print "\n";
print $url_t2;
print "\n";
print $url_t3;
print "\n";
print $url_t4;
print "\n";


#   END CODE ...

All that works on my AIX box at work, but doesn't seem to display
correctly in ActivePerl 5 on my Win32 system.

Here is the output in AIX (seems like the first and third work):

"
~> makeurltest.pl
http://www.news.com/pageq_6.html
http://www.news.com/pageq_6..html
http://www.news.com/pageq_6.html
http://www.news.com/pageq_6.$ext
"

I have written several other scripts that ported perfectly to Windows
ME; is there some quirk with ActivePerl itself that is causing the
problem???


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

Date: 18 Sep 2001 14:59:40 GMT
From: Clay Irving <clay@panix.com>
Subject: Re: HELP!  Having Trouble concatenating or joining and making or building  a url with ActivePerl and the '.' operator.
Message-Id: <slrn9qeocs.dn7.clay@panix1.panix.com>

In article <4b459565.0109171619.fe41924@posting.google.com>, codeslayer wrote:

> The url will be of the form:
> 
> $rtpath/$picrt$count.$ext

Why don't you just print it! :)

> So, here is what these values would be and the url
> that should be produced:
> 
> #######################################
> 
> Given:
> ------
> 
> $rtpath = "http://www.news.com"
> 
> $picrt = "pageq_"
> 
> $count = 06 (or whatever the count is at the time,)
> 
> $ext = "html"
> 
> then, the url produced should be:
> 
> http://www.news.com/pageq_06.html
> 
> #######################################
> 
> The actual url that comes out is:
> 6.html

  #!/usr/local/bin/perl
  
  $rtpath = "http://www.news.com";
  
  $picrt = "pageq_";
  
  $count = "06";
  
  $ext = "html";
  
  print "$rtpath/$picrt$count.$ext\n";

Result:

  http://www.news.com/pageq_06.html

-- 
Clay Irving <clay@panix.com>
And if you are a real looney, you would read the manpage.
- Abigail in c.l.p.misc


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

Date: Tue, 18 Sep 2001 17:07:24 GMT
From: "Dave Palmer" <dave@nospam.stratumonline.com.del>
Subject: html 2 xml
Message-Id: <gbLp7.29279$gU.8943222@news1.rdc1.md.home.com>

Hello all...
I am writing this script that reads an HTML file, and does some basic
transformations so that it could be considered a well formatted XML
document.

Any example of what I'm talking about is... if you come across this line:

<br>

In XML, this is not well formatted... but <br/> is

I just started writing this script and before I get too married to the
technique I am using, I felt it would be benefitial to get some feedback or
some pointers...

Below is the relevant pieces of code that I have so far:

# @lines = all lines of an HTML file
foreach my $line (@lines) {
   if ($line =~ m/\<img (.*)\>/i) {
    my $img_attrs = $1;
    my $new_img_tag = "\<img " . $img_attrs . " \/\>";
    $new_lines .= $new_img_tag . "\n";
   } elsif ($line =~ m/\<br\>/i) {
    $line =~ s/\<br\>/\<br\/\>/g;
    $new_lines .= $line . "\n";
   } elsif ($line =~ m/\<p\>/i) {
    $line =~ s/\<p\>/\<p\/\>/g;
    $new_lines .= $line . "\n";
   } elsif ($line =~ m/\<html\>/i) {
    # do something to ensure there's a closing </html> tag

   } elsif ($line =~ m/\<body/i) {
   # do something to ensure there's a closing </body> tag

   } else {
    $new_lines .= $line . "\n";
   }
  }

This just seems to be getting too nasty looking, and I could be dealing with
thousands of files, and then not only is this nasty its also slow and
painful. So, before I plunge headfirst into this and make a bigger mess...
thought I'd get some advice :)

thanks!

 ./dave

N=R*fs*fp*ne*fl*fi*fc*L




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

Date: Tue, 18 Sep 2001 15:33:41 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: HTML-parsing prob - need regexpression help
Message-Id: <3hieqt4df27au8tg98eq7g1d3h2i2qusb2@4ax.com>

On Tue, 18 Sep 2001, "Boerge Haga" <borgehaga@hotmail.com> wrote:

[Please do not send me courtesy copies of your questions via email
unless you're prepared to pay for consulting - thank you!]

>"Thomas Bätzler" <Thomas@Baetzler.de> wrote in message
>news:<16beqt437gi9afenqjeeo47uuc1c5lc70n@4ax.com>...
>> OTTH, I'd say <a.*?href=\"(.*?)\".*?>(?:<b>)?(.*?)(?:</b>)?</a> might
>> work for your special case.
>
>That worked beautifully, thank you. Now I just need
>one more minor justification to get everything to work.
>My regexp will now also match occurences of:
>
><a href=\"(some url2)\"><img src= etc etc></a>

Of course. Your spec dind't state that you weren't interested in the
<img> tag aswell.

>How can I avoid that match and still match everything from
>above in this discussion?

This is where it gets complicated. The easy way out would either be to
remove all <img> tags beforehand and then require that the <a>/</a>
pair must have text inside them in order to match.

Or you just let the embedded <img> match and remove it after the
match. If there's only an <img> tag, you could reject the match result
altogether.

Anything else is probably bound to get wildly complicated - after all,
there could be any combination of <img> and style tags inside the
<a>/</a> pair. 

Oh, and weren't you going to use HTML::Parser?

#!/usr/bin/perl -w

use strict;
use HTML::Parser;
# use disclaimer("I don't know nutt'n 'bout HTML::Parser");

my $htmlfile = 'whatever';

my( $href, $text );

my @linklist;

 
sub a_start_handler {
  my( $tag, $self, $attr ) = @_;

  # we only act on <a tags  
  return if $tag ne "a";
  
  if( defined( $href = $attr->{href} ) ){
    $self->handler(text => sub { $text = shift; $text =~ s/\n//g; },
"dtext");
    $self->handler( end => \&a_end_handler, "tagname,self" );
  }
  
  foreach my $key ( keys %$attr ){
  #  print ">$key=$attr->{$key}\n";
  }
  
  
}

sub a_end_handler {
  return if shift ne "a";
  my $self = shift;
  
  push @linklist, [ $href, $text ]
    if defined $text && $text !~ /^\s*$/;
  
  $self->handler(end => undef );
  $self->handler(text => undef );
}

my $p = HTML::Parser->new(api_version => 3);

$p->handler( start => \&a_start_handler, "tagname,self,attr" );

$p->unbroken_text( 1 );

$p->parse_file( $htmlfile ) || die $!;

foreach my $link ( @linklist ){
  print "$link->[0]: $link->[1]\n";
}
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


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

Date: Tue, 18 Sep 2001 08:10:38 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: local() breaks with imported vars (Exporter bug?)
Message-Id: <3BA747CE.CCC0789C@home.com>

Martien Verbruggen wrote:
> 
> On Mon, 17 Sep 2001 14:43:39 -0500,
>         Michael Carman <mjcarman@home.com> wrote:
> >
> > [...] "*var = *FOO" seems to bind more deeply, such that the
> > two glob names are truly synonymous. Where is this documented?
> 
> perldata and perlmod both state that C< *foo = *bar; > creates an
> alias for the symbol table entry itself, not for its constituents.
> 
> perldata: Typeglobs and Filehandles
> perlmod: Symbol Tables

Hrm. I read both of those several times while trying to work this out.
 
> I agree that it could be a bit more clear.

Indeed. After yet another reading -- a very critical one this time -- I
believe I see the portions you're referring to. There are a few places
on both pages that _hint_ at this behavior. Unfortunately, it takes a
carefully strict interpretation to pick up on this and most of the
documentation is not that precise. For example, perlmod states

        *dick = \$richard;

    ... makes $richard and $dick the same variable ...

which is why I expected something like "local($dick)" to work.

> On the other hand, it is obscure enough not to be needed very
> often.

True. Perhaps by the time one encounters this (and hasn't been using bad
coding practices) they're supposed to be able to figure it out. A test
before one can progress to the next level of Perl hackerdom. :) Still,
I'd like to see a caveat somewhere that says when this doesn't work.

Thanks for the insight, all.

-mjc


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

Date: 18 Sep 2001 10:17:37 -0400
From: stanb@panix.com (Stan Brown)
Subject: MAJOR problems with Storable, and pipe. Help Please.
Message-Id: <9o7l21$j38$1@panix1.panix.com>

I'm trying desperately to finish a failry large perl script that uses DBI
to extract data from an Oracle DB, and uses PerlTK as the user interface.

Because this data can be failry large, I have the script fork a child to do
the actual DB fetch, with the intent that this will still allow teh parent
to update the TK widgets. 

The extracted records are ent over a pipe using Storable (store_fd, and
fd_retriev). What's being sent is a reference to an array, for each record
set (row).

My problem is that I find that Tk::fileevent is getting trigered, and then
the callback is blocking on fd_retrieve. I've played around with autflush
on the wrtier end of the pipe, but sometimes this results in a Storable
error (it thinks the data is bad).

How can I assure that:

1. store_fd only writes ccomplete rows to the pipe
2. fd_retrieve does not block?

I will be happy to share the apropriate snippets of code, and dbuging ifno
to anyone, to help with diagnosing what I am doing wrong, but I'm not going
to post it here, since I got flamed for doing that yesterday. After getting
flamed a couple of days agao for _not_ showing the code.

Thanks to any kind soul, that is willling to help educate me on this.


-- 
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
						-- Benjamin Franklin


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

Date: Tue, 18 Sep 2001 13:41:48 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Need help with this regex problem:
Message-Id: <pnjeqtgb5166gid19s59lnhn7krjim7sbk@4ax.com>

Anno Siegel wrote:

>    if ( length( $line) == 11 and $line =~ /^\d+ *$/ ) {

This length doesn't account for the newline.

-- 
	Bart.


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

Date: Wed, 19 Sep 2001 00:14:09 +0800
From: "hwchui" <hwc33@hotmail.com>
Subject: newbie question - why it gives filehandle error?
Message-Id: <9o7rq7$m082@imsp212.netvigator.com>

I don't no idea why it gives me an error message like

"print() on closed filehandle main::FH2 at ./tb.pl line 16."

What I understand is, FH2 in ta.pl should be closed before
return back to tp.pl so what goes wrong?


There are two files and they are:

#----------------------------------------
#   ta.pl
#-----------------------------------------
#!/usr/bin/perl -w


sub doSomething {

 ($file1,$file2) = @_;

 print "file1 = $file1\n";
 print "file2 = $file2\n";

 local(*FH1, *FH2);

 open (FH1, "< $file1") || die "Can't Open file $file1: $!\n";
 open (FH2, "> $file2") || die "Can't Open file $file2: $!\n";

 select FH2;

 while (<FH1>) {
  print FH2 $_;
 }

 close FH1;
 close FH2;
}
1;

#----------------------------------------------------------------------
#         tb.pl
#----------------------------------------------------------------------
#!/usr/bin/perl -w


require "ta.pl";


$myf1 = shift @ARGV;
$myf2 = shift @ARGV;

print $myf1, "\n";
print $myf2, "\n";

doSomething($myf1,$myf2);


print "what happen?\n";    #It doesn't print to FH2 which should be closed
in ta.pl










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

Date: Tue, 18 Sep 2001 17:12:47 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: newbie question - why it gives filehandle error?
Message-Id: <3BA77F52.3F57588B@acm.org>

hwchui wrote:
>  select FH2;

This selects FH2 as the filehandle to use for subsequent print
operations that would normally go to STDOUT. This is completely
unnecessary, since you give an explicit filehandle in your copy
loop anyway. Just get rid of it.

FH2 is still selected when doSomething returns, so when the print
operation in the caller attempts to print to it, you get the error
message.

> print "what happen?\n";

  print STDOUT "what happen?\n";

would work here.

-- Dave Tweed


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

Date: 18 Sep 2001 11:45:54 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: newbie question - why it gives filehandle error?
Message-Id: <m366agmoql.fsf@dhcp9-161.support.tivoli.com>

On Wed, 19 Sep 2001, hwc33@hotmail.com wrote:

> I don't no idea why it gives me an error message like
> 
> "print() on closed filehandle main::FH2 at ./tb.pl line 16."
> 
> What I understand is, FH2 in ta.pl should be closed before
> return back to tp.pl so what goes wrong?

It is, but you still had it "select"-ed.  Get rid of the call to
select and the problem will go away.

[code with useless call to select snipped]

-- 
Ren Maddox
ren@tivoli.com


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

Date: Tue, 18 Sep 2001 13:39:50 GMT
From: iowa_song88.remove_eights_and_this@hotmail.com (Weston Cann)
Subject: object to string and back to object.....
Message-Id: <iowa_song88.remove_eights_and_this-1809010741490001@67.westvalleycity-02rh15rt-ut.dial-access.att.net>

I'm looking for a solution that will enable me to dump arbitrary
perl data structures to a string, and transform that string, in turn,
back into an arbitrary data structure.

Data::Dumper and Data::Dump are close, but there's one problem: I'd like
some mechanism other than eval for transforming the string representation
back to a data structure. The reason is that it's likely I'll be passing
the string representation as a parameter from a web based form, and letting
people execute arbitrary perl code from a web form generally won't do. :)

Is there anything out there that'll do that?


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

Date: 18 Sep 2001 07:48:34 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: object to string and back to object.....
Message-Id: <m166agh7wd.fsf@halfdome.holdit.com>

>>>>> "Weston" == Weston Cann <iowa_song88.remove_eights_and_this@hotmail.com> writes:

Weston> I'm looking for a solution that will enable me to dump arbitrary
Weston> perl data structures to a string, and transform that string, in turn,
Weston> back into an arbitrary data structure.

Weston> Data::Dumper and Data::Dump are close, but there's one
Weston> problem: I'd like some mechanism other than eval for
Weston> transforming the string representation back to a data
Weston> structure. The reason is that it's likely I'll be passing the
Weston> string representation as a parameter from a web based form,
Weston> and letting people execute arbitrary perl code from a web form
Weston> generally won't do. :)

There's Data::Denter (cpan) which can handle a subset of what Data::Dumper
does.

There's the Data::Undump in the RCGI distribution (cpan) which "eval"s
Data::Dumper-ized stuff in a "Safe" compartment.

And there's my recent Linux Magazine column where I use
Parse::RecDescent to parse Data::Dumper output, not fast, but rather
complete: see http://www.stonehenge.com/merlyn/LinuxMag/, column 29.

There may be others, but that's what I found when I was researching my
recent column.

print for "Just another Perl hacker,"

-- 
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: 18 Sep 2001 10:39:42 -0700
From: google@utahvalleymusic.com (Weston Cann)
Subject: Re: object to string and back to object.....
Message-Id: <3e5aa16c.0109180939.713195c5@posting.google.com>

merlyn@stonehenge.com (Randal L. Schwartz) wrote in message news:<m166agh7wd.fsf@halfdome.holdit.com>...

> There's Data::Denter (cpan) which can handle a subset of what 
> Data::Dumper does.
> 
> There's the Data::Undump in the RCGI distribution (cpan) which "eval"s
> Data::Dumper-ized stuff in a "Safe" compartment.
> 
> And there's my recent Linux Magazine column where I use
> Parse::RecDescent to parse Data::Dumper output, not fast, but rather
> complete: see http://www.stonehenge.com/merlyn/LinuxMag/, column 29.
> 
> There may be others, but that's what I found when I was researching my
> recent column.

Remind me to read your column more regularly..... :)

(or in other words, thanks)


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

Date: 18 Sep 2001 10:28:15 -0700
From: delanthear@yahoo.com (Del)
Subject: Re: Objects and Sockets
Message-Id: <999063fd.0109180928.2c304955@posting.google.com>

> You can build your object around a hash ref and store your
> instance-specific data like an associated socket in that hash.
> 
> Consider this standard constructor skeleton:
> 
> sub new {
>   my $proto = shift;
>   my $class = ref( $proto ) || $proto;
>   my $self = {};
> 
>   # do something
> 
>   return $self;
> }
> 
> Each method of the object will receive this hash ref as the first
> argument when it is called.

Sorry, 

I don't really understand that example.   How do you store a
filehandle within a hash?  I don't remember any examples of doing
this!  Could you point me to a working example so I can get my head
around it?

eg, 
socket(SESSION, PR_INET, SOCK_STREAM, getprotobyname('tcp')) || die
"$!";

creates a socket, usable by the filehandle SESSION, but how would I
store that within the object for later use?

thanks for the help!


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

Date: 18 Sep 2001 11:00:51 -0700
From: weedmonster_99@yahoo.com (codeslayer)
Subject: Open Multiple URL's or Web Pages with Perl or JPG or gifs or pictures or images:
Message-Id: <4b459565.0109181000.19305984@posting.google.com>

Here is a script I wrote to open multiple urls or web pages at a time.
 It is opens sequetially numbered documents.

This eliminates the user having to click on web pages to open them;
all they have to do is enter some constants and a numerical range and
the script will do the rest.



#!/usr/bin/perl -w

################################################
# DEFINE TEST VARIABLES:
################################################
#
$rtpath = "http://www.news.com";

$picrt = "pageq_";

$count = 06;	#(or whatever the count is at the time,)

$picsuf = ();

$ext = "html";

################################################
# GET INPUT FROM USER:
################################################
#

print "Enter the start number: ";
$start = <STDIN>;
chomp $start;

print "Enter the ending number: ";
$end = <STDIN>;
chomp $end;

print "Enter the root path of the url: \n";
$rtpath = <STDIN>;
chomp $rtpath;

print "Enter the static doc name root part: ";
$picrt = <STDIN>;
chomp $picrt;

print "Enter the doc name suffix:";
$picsuf = <STDIN>;
chomp $picsuf;

print "Enter the extension: ";
$ext = <STDIN>;
chomp $ext;

&openmultiwindows;

$hold = <STDIN>;

sub createurl {

################################################
# VARIOUS ATTEMPTS TO CREATE THE URL:
################################################

$url_t1 = "$rtpath/$picrt$count$picsuf.$ext";

$url_t2 = "$rtpath/" . "$picrt" . "$count" . "$picsuf" . ".$ext";

################################################
# PRINT URL TEST OUTPUT:
################################################
#
# NOTE:		These worked on my AIX box at
#		work, but do not work on my
#		PC for some reason.
#
print "\n\n";
print $url_t1;
print "\n\n";
print "another version ...\n";
print $url_t2;
print "\n";

}



sub openmultiwindows {

   for $count ($start..$end) {

   &createurl;
   
   &openurl;

   print "opened: $url_t1\n\n";

   }

}


sub openurl {

$page = $url_t1;
$file = 'file:///afs/rchland.ibm.com/usr3/v2cib484/tmp/somefile';
#system ("explorer $file");

system ("netscape $page");

#$hold = <STDIN>;

}


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

Date: Tue, 18 Sep 2001 14:34:08 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Perl (slurping) is TOO much fun
Message-Id: <9o7m10$vlc$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Uri Guttman 
<uri@sysarch.com>], who wrote in article <x7iteiectd.fsf@home.sysarch.com>:
> hmm, do you ever use a perl module or require one? those files are
> slurped in whole as the perl parser doesn't work line by line.

Perl parser works line-by-line.  Just think about <DATA>.

Hope this helps,
Ilya


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

Date: 18 Sep 2001 07:50:02 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Persistence in Perl
Message-Id: <m1y9ncft9h.fsf@halfdome.holdit.com>

>>>>> "Venu" == Venu  <spaceme_2001@yahoo.com> writes:

Venu> Hi all,
Venu> I want to know is there any Persistence mechanism exists in Perl? 

Venu> Suppose i have a search where i need to display the results 10 per
Venu> page. Now i got 100 matches and need to display in 10 pages. Now here
Venu> generally what i'm doing now is store 10 records in each text file
Venu> (total 10 files) and display accordingly. But there are lot of
Venu> problems in this. I want to know, is there any way so that i can store
Venu> all the 100 matches in an array or something so that i can display
Venu> through perl? I heard there is a module (persistence module) for this?
Venu> Any one has ever faced this problem? If so please suggest me the way.

Sounds like what I did on one of my very early WebTechniques columns...
see column 02 in http://www.stonehenge.com/merlyn/WebTechniques/.

print "Just another Perl hacker,"

-- 
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: Tue, 18 Sep 2001 15:59:38 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Persistence in Perl
Message-Id: <careqt00knq87geeb9hq7noua53jcqpes5@4ax.com>

Venu wrote:

>I want to know is there any Persistence mechanism exists in Perl? 

Yes. There's the tie() mechanism, in perl4 it was dbmopen(). See perldoc
-f tie, perldoc perltie, perldoc AnyDBM_File.

>Suppose i have a search where i need to display the results 10 per
>page. Now i got 100 matches and need to display in 10 pages. Now here
>generally what i'm doing now is store 10 records in each text file
>(total 10 files) and display accordingly.

I wouldn't do this for caching, especially not with mutliple users at
the same time. How costly is it to do the search every time?

Anyway, as someone else amready wriote, Storable and Data::Dumper can be
used to save perl datastructures to files.

And look into the module Memoize on CPAN. It might just do what you
want. Memoization is storing constant results for functions into perl
datastructures, in order to avoid calculating it again. From the
assisting modules list, I gather it includes ways to make results
persistent, and to expire them after some time. It looks very
interesting.

	<http://search.cpan.org/search?dist=Memoize>

-- 
	Bart.


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

Date: Tue, 18 Sep 2001 19:02:16 +0100
From: Miguel Manso <mmanso@prodigio.com>
Subject: Re: Persistence in Perl
Message-Id: <3BA78C28.3000603@prodigio.com>

Hi wonder if you can use Memoize with object methods has well... that 
would be great...


Bart Lateur wrote:

> Venu wrote:
> 
> 
>>I want to know is there any Persistence mechanism exists in Perl? 
>>
> 
> Yes. There's the tie() mechanism, in perl4 it was dbmopen(). See perldoc
> -f tie, perldoc perltie, perldoc AnyDBM_File.
> 
> 
>>Suppose i have a search where i need to display the results 10 per
>>page. Now i got 100 matches and need to display in 10 pages. Now here
>>generally what i'm doing now is store 10 records in each text file
>>(total 10 files) and display accordingly.
>>
> 
> I wouldn't do this for caching, especially not with mutliple users at
> the same time. How costly is it to do the search every time?
> 
> Anyway, as someone else amready wriote, Storable and Data::Dumper can be
> used to save perl datastructures to files.
> 
> And look into the module Memoize on CPAN. It might just do what you
> want. Memoization is storing constant results for functions into perl
> datastructures, in order to avoid calculating it again. From the
> assisting modules list, I gather it includes ways to make results
> persistent, and to expire them after some time. It looks very
> interesting.
> 
> 	<http://search.cpan.org/search?dist=Memoize>
> 



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

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


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