[22512] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4733 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 20 03:05:37 2003

Date: Thu, 20 Mar 2003 00:05:09 -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, 20 Mar 2003     Volume: 10 Number: 4733

Today's topics:
    Re: Anyone For Golf? (Resistor Colour Codes) (Ton Hospel)
    Re: Anyone For Golf? (Resistor Colour Codes) <goldbb2@earthlink.net>
        Can't access array element in Class::Struct structure (Carlton Brown)
    Re: Can't access array element in Class::Struct structu (Tad McClellan)
    Re: Can't access array element in Class::Struct structu (Carlton Brown)
        Differences between anonymous subs and named subs <bernie@fantasyfarm.com>
    Re: Differences between anonymous subs and named subs <goldbb2@earthlink.net>
    Re: Find&Replace only in a certain scope (Tad McClellan)
    Re: Find&Replace only in a certain scope <mstep@t-online.de>
    Re: Find&Replace only in a certain scope <jurgenex@hotmail.com>
    Re: How to include data stamps in a script?? <tore@aursand.no>
        Need a little help with a short script (HKVandal)
        Open file and print out contents from array (Jacques Veldhuijzen)
    Re: Open file and print out contents from array <jurgenex@hotmail.com>
    Re: Out of memory (Ritesh Shah)
        Reverse assignment operator <torelg@start.no>
    Re: Reverse assignment operator <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: Reverse assignment operator <tassilo.parseval@post.rwth-aachen.de>
    Re: Socket Problem In Perl <spp@monaco377.com>
        Text::ParseWords or Text::CSV (david)
    Re: Text::ParseWords or Text::CSV <tore@aursand.no>
    Re: Why is alarm() waiting for inconsistent periods of  (Carlton Brown)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 20 Mar 2003 03:23:53 +0000 (UTC)
From: thospel@mail.dma.be (Ton Hospel)
Subject: Re: Anyone For Golf? (Resistor Colour Codes)
Message-Id: <b5bc89$r1$1@post.home.lunix>

printf"%d%d%.*d\n",map{vec crypt(rQdlz0,reverse),18,4}@ARGV

hard newline makes this 58 in normal golf counting.
(the crypt is hardly optimal, but it's the first one I found.
Should be possible to reduce this by about 6 more chars)


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

Date: Thu, 20 Mar 2003 02:20:26 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Anyone For Golf? (Resistor Colour Codes)
Message-Id: <3E796BBA.8AD02732@earthlink.net>



Ton Hospel wrote:
> 
> printf"%d%d%.*d\n",map{vec crypt(rQdlz0,reverse),18,4}@ARGV
> 
> hard newline makes this 58 in normal golf counting.
> (the crypt is hardly optimal, but it's the first one I found.
> Should be possible to reduce this by about 6 more chars)

My god, that is evil!

Not to mention, very cool.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: 19 Mar 2003 18:18:50 -0800
From: carltonbrown@hotmail.com (Carlton Brown)
Subject: Can't access array element in Class::Struct structure
Message-Id: <aa611a32.0303191818.2653b3af@posting.google.com>

Problem:  Using a simple snippet of example code, I am unable to
assign or access array attributes of a struct.   Scalars work fine.

This should be simple but it continues to elude me.   I'm trying to
make a simple working example of Class::Struct, but even the barest
one won't work.  I am starting to think that perhaps both the array
assignment and accessor are wrong, but I have no proof, as I have
never seen this working.

(Yes, this is the second time I asked, I screwed up the first time by
posting an obvious typo.  This time I have reverse-copied what I have
pasted this time and it still fails.  So if anyone copies this code
verbatim and it works, let's compare versions!  Mine is 5.6.1 on SunOS
5.8)

The output of this code is:
Aragorn is of the race of Man.      # Correct
His aliases are: .                  # Incorrect.  3 aliases should be
displayed.
His most famous alias is Person=HASH(0xf096c)->aliases(0)

As far as I can tell, this is all according to the Class::Struct man
page.
I must be missing something, but what?

SCRIPT CODE:
#!/usr/bin/perl
use warnings;
use strict;
use Person;
my $him;
$him = Person->new;
$him->name("Aragorn");
$him->race("Man");
$him->aliases( ["Strider", "Estel", "Elessar"] );
printf "%s is of the race of %s.\n", $him->name, $him->race;
print "His aliases are: ", join(", ", @{$him->aliases}), ".\n";
print "His most famous alias is $him->aliases(0)\n";

MODULE CODE:
package Person;
use Class::Struct;
struct Person => {    # create a definition for a "Person"
    name    => '$',   #    name field is a scalar
    race    => '$',   #    race field is also a scalar
    aliases => '@',   #    but aliases field is an array ref
};
1;

A thousand thanks.   I know I'm a so-so programmer but I'd hate to
think I'm not even competent enough to copy code out of a book :)


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

Date: Wed, 19 Mar 2003 21:18:23 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Can't access array element in Class::Struct structure
Message-Id: <slrnb7icnv.56m.tadmc@magna.augustmail.com>

Carlton Brown <carltonbrown@hotmail.com> wrote:

> (Yes, this is the second time I asked, I screwed up the first time by
> posting an obvious typo.  


And by not reading the Posting Guidelines.   :-)

> So if anyone copies this code
> verbatim and it works, let's compare versions!  Mine is 5.6.1 on SunOS
> 5.8)


On Linux (RH 7.2) it works with perl 5.8.0, but fails the same way
as yours with 5.6.1.



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


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

Date: 19 Mar 2003 22:22:02 -0800
From: carltonbrown@hotmail.com (Carlton Brown)
Subject: Re: Can't access array element in Class::Struct structure
Message-Id: <aa611a32.0303192222.189fd5e2@posting.google.com>

tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnb7icnv.56m.tadmc@magna.augustmail.com>...
> 
> On Linux (RH 7.2) it works with perl 5.8.0, but fails the same way
> as yours with 5.6.1.

A thousand thanks.  Now I know I'm not crazy.  It's puzzling
considering this edition of the Camel book was released before 5.8.0,
but that's a mystery for the ages.

If anyone can tell me the proper technique in 5.6.1, I'd be grateful. 
Implementing 5.8.0 soon is unlikely for us.

OR, if there's a better way to implement complex data structures, I'd
love to hear it.  This seems more likely.  In my experience, if I
can't find much info on a technique, that means the rest of the world
already figured out a better way to do it.


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

Date: Wed, 19 Mar 2003 23:16:53 -0500
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Differences between anonymous subs and named subs
Message-Id: <37F01E873233F881.43B25968CD0482EA.49366004220AD267@lp.airnews.net>

My recent inquiry about a problem I was having with a closure ended up
turning on something I actually didn't understand -- which is that
second-level *named* subroutines don't apparently handle closures properly,
but second level *anonymous* subroutines do.  So:
   sub a
   {  my $x ;
      sub b { return $x; }  # This is *NOT* a closure to the $x in a
      my $c = sub { return $x; }  # This *is* closured to the $x in a

I don't exactly understand what Perl does in the first case [the 'named'
sub] other than that it was not what I wanted so I changed to an anonymous
sub and it all works as I expected..:o)  BUT: it got me wondering... are
there any other semantic differences in what you get when you compile a
second-level subroutine 'named' versus 'anonymous'.... Indeed, are there
any such differences with top-level subroutines?   I'm just trying to get
an intuition for what's going on here...

  /Bernie\
-- 
Bernie Cosell                     Fantasy Farm Fibers
bernie@fantasyfarm.com            Pearisburg, VA
    -->  Too many people, too few sheep  <--          


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

Date: Thu, 20 Mar 2003 02:09:40 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Differences between anonymous subs and named subs
Message-Id: <3E796934.622F6AF4@earthlink.net>

Bernie Cosell wrote:
> 
> My recent inquiry about a problem I was having with a closure ended up
> turning on something I actually didn't understand -- which is that
> second-level *named* subroutines don't apparently handle closures
> properly, but second level *anonymous* subroutines do.  So:
>    sub a
>    {  my $x ;
>       sub b { return $x; }  # This is *NOT* a closure to the $x in a
>       my $c = sub { return $x; }  # This *is* closured to the $x in a

Actually, 'b' *is* a closure to the $x -- but only to the $x in the
first invocation of 'a'.

> I don't exactly understand what Perl does in the first case [the
> 'named' sub] other than that it was not what I wanted so I changed to
> an anonymous sub and it all works as I expected..:o)

It's doing something like this:

sub a {
   my $x;
   BEGIN { *b = sub { return $x } }
   my $c = sub { return $x; }
}

> BUT: it got me wondering... are there any other semantic differences
> in what you get when you compile a second-level subroutine 'named'
> versus 'anonymous'.... Indeed, are there any such differences with
> top-level subroutines?   I'm just trying to get an intuition for
> what's going on here...

A named sub gets created the instant it's seen -- the moment you get to
the final "}", the sub exists (and if there're any lexicals in the
enclosing scope(s), it can see them *as they are at that instant*).

An anonymous sub, though doesn't -- it gets parsed into a template, and
doesn't get instantiated until runtime.  Obviously, each time that it's
instantiated to create a new coderef, any lexicals it uses from
enclosing scopes are shared with it, as they are at the time of
instantiation.

As to sub 'b' only seeing the first version of $x, think about this bit
of code:

   sub foo {
      my $x;
      BEGIN { $x = "wierd!\n" }
      print $x || "[undef]\n";
   }
   foo(); foo(); foo();

That BEGIN block is modifying the same version of $x as your 'b' sub
sees.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Wed, 19 Mar 2003 21:11:52 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Find&Replace only in a certain scope
Message-Id: <slrnb7icbo.56m.tadmc@magna.augustmail.com>

Marek Stepanek <mstep@t-online.de> wrote:
> On 19.03.2003 10:27 Uhr, in article b59d5u$ahu$1@mamenchi.zrz.TU-Berlin.DE,
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote:
>> 
>> Your problem isn't how to limit the effect of a text substitution to
>> part of a string.  That is trivial:
>> 
>>   substr( $str, $start, $length) =~ s///;
>> 
>> deals only with the substring and leaves other parts alone.  Your
>> problem is how to find the substring(s) you want to work on.  This
>> is where HTML parsing enters because regex matching just doesn't cut
>> it.


> finally some answers! But a little bit disappointing. 


Yes, it _is_ disappointing to discover that HTML is much harder
to parse that you thought it was, but that is not Perl's fault.


> I thought - I am only
> a Perl beginner - that the following should be possible:
> 
> look for _keyword_ 

   perldoc -f index


> look behind the closest <table
> set the offset of it in a $beginning_variable
> look forward to the closest </table
> set it to the $end_variable


That will not work correctly if <table>s are nested.


> ... the rest (the loop) would be easy. 


But what you would have come before "the rest" is incorrect,
so what comes after it does not matter much.


> Even for me as a beginner.


Parsing HTML correctly is difficult even for an expert, in any
programming language, because the rules for parsing HTML are difficult.


> so: is this not possible to set an offset 


   perldoc -f index


> to a variable an search between
> two positions ???


   perldoc -f substr

as above.


> (I am already doubting about the power of Perl ... )


You have misunderstood where the cause of the difficulty is.

I am doubting your understanding of the data that you mean to process.

Your algorithm would fail on something as simple as:

   <p> _keyword_ </p>
   <!-- I am not a <table -->
   <p> other stuff that should NOT be changed</p>
   <table>
   </table>

As it would change anything in this part:

                  <table -->
   <p> other stuff that should NOT be changed</p>
   <table>
   </table>

or with:

   <table>
      <table>
      </table>
   </table>
   
As it would change anything in this part:

   <table>
      <table>
      </table>

and miss changing things in the last bit.

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


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

Date: Thu, 20 Mar 2003 07:16:48 +0100
From: Marek Stepanek <mstep@t-online.de>
Subject: Re: Find&Replace only in a certain scope
Message-Id: <BA9F1B60.5A2F%mstep@t-online.de>

On 20.03.2003 4:11 Uhr, in article
slrnb7icbo.56m.tadmc@magna.augustmail.com, "Tad McClellan"
<tadmc@augustmail.com> wrote:

Thank you Tad and to all who took the pain to answer my beginner questions.

I see the problem. Would it be possible to set an position of the closest
<table to _keyword_ (backwards), if my html is not nested? _keyword_ is only
appearing in <tables and these <tables are not nested ... And then the
position of the closest </table ? Can't believe it, that this is not
possible in Perl ...

I am really disappointed from the "power of Perl" :-( I bought nearly every
Perl-book and could not see an solution to my problem. For that reason I was
bothering this group, insisting on my question ...

So, I will do my changes (200 different html-pages!) with the help of BBEdit
and Applescript ...

thanx again


marek


______________________________________________________________________
___PODIUM_INTERNATIONAL_//_the_embassy_for_talented_young_musicians___
_______Marek_Stepanek__mstep_[at]_PodiumInternational_[dot]_de________
__________________http://www.PodiumInternational.de___________________
______________________________________________________________________






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

Date: Thu, 20 Mar 2003 07:04:04 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Find&Replace only in a certain scope
Message-Id: <EJdea.60986$iq1.42978@nwrddc02.gnilink.net>

Marek Stepanek wrote:
> I see the problem. Would it be possible to set an position of the
> closest <table to _keyword_ (backwards), if my html is not nested?
> _keyword_ is only appearing in <tables and these <tables are not
> nested ... And then the position of the closest </table ? Can't
> believe it, that this is not possible in Perl ...
>
> I am really disappointed from the "power of Perl" :-( I bought nearly
> every Perl-book and could not see an solution to my problem. For that
> reason I was bothering this group, insisting on my question ...

This is not a problem with Perl. Contrary to popular believe parsing HTML is
rocket science. And it is hard in any programming language. No matter what
you think, it can not be done correctly with a few REs. Perl may make it
easier to write an HTML parser, but it doesn't make it so trivial, that you
could tackle the problem without extensive knowledge of compiler
construction (or at least parser design).
Again, you are blaming the messenger,

> So, I will do my changes (200 different html-pages!) with the help of
> BBEdit and Applescript ...

Why don't you leverage the existing work that was done by people in the know
who wrote HTML::Parser so that people who are not compiler experts can parse
HTML easily, too.
There is no need to re-invent the wheel.

jue




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

Date: Thu, 20 Mar 2003 04:34:59 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: How to include data stamps in a script??
Message-Id: <pan.2003.03.20.03.29.38.971529@aursand.no>

On Wed, 19 Mar 2003 14:18:49 -0800, John Smith wrote:
> I am writing a perl script that runs several times a day. Every time it
> runs, it needs to give an output file like below:
> 
> test1_links_03182003[1].html when the script is run first time; (where
> 03182003 is today's date and [1] reperesents that the script is run for
> the first time today)
> test1_links_03182003[2].html when the script is run second time;
> test1_links_03182003[3].html when the script is run third time;
> test1_links_03182003[4].html when the script is run fourth time;

In other words, you want to generate an unique filename each time.  Let's
have a look at that, but first:

Why do you want to use 'MMDDYYYY' as date format?  Stick with 'YYYYMMDD'
is my suggestion.

To create the unique filename, follow this thinking:

  my $count = 1;
  while ( -e $filename . '_' . $date . '[' . $count . ']' . '.html' ) {
      $count++;
  }

Not so hard.  To parse your filename (ie. 'test1_links.html' in your
example), you could use File::Basename to extract path, filename and
suffix.

For the date part, you'll get going with 'localtime()'.


-- 
Tore Aursand


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

Date: 19 Mar 2003 22:31:17 -0800
From: hkvandal@shackmail.com (HKVandal)
Subject: Need a little help with a short script
Message-Id: <8dbe2cad.0303192231.1cc76cc1@posting.google.com>

Hi trying to make my first productive script, it (in theory)renames
file extensions in win32, script is below

print "Type in name of Directory, ie. C:\\music\\\n";
chomp($dirname=<STDIN>);
print "Type in name of extension to replace ie. mp3 (no period)";
chomp($old=<STDIN>);
print "Type in name of the new extension ie. mpg";
chomp($new=<STDIN>);
opendir (DIR, $dirname) or die "can't open dir $!";
while(defined($file=readdir(DIR))){
$old_file=$file;
if($file=~/.*\.(.*)/){
$currext=$1;
if($currext=$old){
$file=~/(.*)\..*/;
$currfile=$1;
$new_file=$currfile . "\." . $new;
rename ($old_file, $new_file) or die "$!";
}
}
}
closedir(DIR);



I get the following error when I run it

Permission denied at c:\docs\ext.pl line 16, <STDIN> line 3.

Any help is greatly appreciated


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

Date: 19 Mar 2003 22:34:00 -0800
From: veld@interparts-cp.nl (Jacques Veldhuijzen)
Subject: Open file and print out contents from array
Message-Id: <cb594a0f.0303192234.2a17e526@posting.google.com>

I did create the following script detail

	open (IN, "$text_url"); 
	@lines = <IN>; # Slurp file into array
	print MAIL @lines;
        close(IN); 

My intention is to open a file with text to be included into a e-mail
message to be sent to a recipient.

When i use
	print MAIL "'$text_url'\n"; 
the value of this variable appears in the e-mail correctly.

The instruction 
        print MAIL @lines;
has no effect at all.

How can i make this work easily


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

Date: Thu, 20 Mar 2003 07:10:33 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Open file and print out contents from array
Message-Id: <JPdea.61022$iq1.22538@nwrddc02.gnilink.net>

Jacques Veldhuijzen wrote:
> I did create the following script detail
>
> open (IN, "$text_url");

Useless use of quotes.
Missing
    or die "Cannot open $text_url because $!\n"

> @lines = <IN>; # Slurp file into array
> print MAIL @lines;
>         close(IN);
>
> My intention is to open a file with text to be included into a e-mail
> message to be sent to a recipient.
>
> When i use
> print MAIL "'$text_url'\n";
> the value of this variable appears in the e-mail correctly.
>
> The instruction
>         print MAIL @lines;
> has no effect at all.

Then I would guess that @lines doesn't contain any lines.
Why didn't you check if the open was successful? If it failed then @lines
would be empty.

jue




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

Date: 19 Mar 2003 20:11:15 -0800
From: ritesh_shah2000@yahoo.com (Ritesh Shah)
Subject: Re: Out of memory
Message-Id: <243164f.0303192011.ec0a7d9@posting.google.com>

Thanks all for their responses. 

> Almost always it is not necessary to re-initialize variables within a loop.
> If you need to do something like that, you can usually put the
> "my" inside the loop in place of the re-initialization.  This can prevent a
> host of bugs.  (you are using strict, right?).  My guess is that one of
> your variables isn't really getting re-initialized to empty after a
> checkpoint.
 
Gunnar and you are right. One of arrays' index is running into 10s of
millions and that's causing "Out of memory". Thanks for pointing out
other improvements in the code.

Ritesh


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

Date: Thu, 20 Mar 2003 06:22:13 +0000 (UTC)
From: Tore Gustavsen <torelg@start.no>
Subject: Reverse assignment operator
Message-Id: <slrnb7ini1.2b2.torelg@localhost.localdomain>

Sometimes I'm a little fascinated when I see code that looks like
English. While reading the camelbook, I started wondering if

    $nick isthe $users{name};

could be made to perform the same thing as

    $users{name} = $nick;

A poor example, but you get the idea.  Anyone know if it can be done?

-- 
Tore Gustavsen,
torelg@start.no            


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

Date: Thu, 20 Mar 2003 06:42:29 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Reverse assignment operator
Message-Id: <Xns93444DA2F3CC6elhber1lidotechnet@62.89.127.66>

Tore Gustavsen wrote:

> Sometimes I'm a little fascinated when I see code that looks like
> English. While reading the camelbook, I started wondering if
> 
>     $nick isthe $users{name};
> 
> could be made to perform the same thing as
> 
>     $users{name} = $nick;
> 
> A poor example, but you get the idea.  Anyone know if it can be done?


If you're willing to use:


  $nick, isthe ($users{name});


or


  $nick => isthe ($users{name});


then here's a very silly program which will do what you want:


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

my $val = 'This is a test';
my $nick;

# Turn off warnings here if you want
$nick, isthe( $val);
# Turn them back on here

print $nick, "\n";

sub isthe {
  my $line = (caller())[2];
  my $file = (caller())[1];

  @ARGV = ($file);
  while (<>) {
    if ($. == $line) {
      if (m/(\$[^,]+),\s*isthe\(\s*(\$\w+)\s*\)/) {
        eval "$main::$1 = $main::$2";
        return;
      }
    }
  }
} 
------------------


-- 
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'



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

Date: 20 Mar 2003 07:42:09 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Reverse assignment operator
Message-Id: <b5brch$737$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Tore Gustavsen:

> Sometimes I'm a little fascinated when I see code that looks like
> English. While reading the camelbook, I started wondering if
> 
>     $nick isthe $users{name};
> 
> could be made to perform the same thing as
> 
>     $users{name} = $nick;
> 
> A poor example, but you get the idea.  Anyone know if it can be done?

In Perl you currently can't define your own operators and in your case
'isthe' would have to be an operator. But you can cheat by using a
source filter (this is now the first time I used them myself). Here is a
little module that implements 'isthe' where both operands are simple
scalars:

    package IsThe;

    my $VAR = '(\$[A-Za-z_][A-Za-z_0-9]+)';
    use Filter::Simple
        sub {
            s/$VAR\s+isthe\s+$VAR/IsThe::isthe(\\$2, $1)/;
        };

    sub isthe { ${ $_[0] } = $_[1] }
    __END__

And in your scripts you now have a shiny new operator:

    use IsThe;

    my $var1 = "hello";
    my $word;

    $var1 isthe $word;
    print $word, "\n";
    __END__
    hello

The source filter works by running through your script and replacing
certain lines with something perl can parse. If you change the
filter-sub to

    sub {
        s/$VAR\s+isthe\s+$VAR/IsThe::isthe(\\$2, $1)/ && print;
    }

you can see what happens:

    my $var1 = "hello";
    my $word;

    IsThe::isthe(\$word, $var1);
    print $word, "\n";
    hello

The line

    $var isthe $word;

has been changed to
    
    IsThe::isthe(\$word, $var1);

That's a simple subroutine call. IsThe::isthe() merely assigns the
second value to the variable referred to by the first parameter.

A more general filter however that could transform something like

    do { extremely_complicated_expression;
         ...;
         ...;
    } isthe $var->[0]->[0]->[0]->[0];

is much harder to write since you'd need to parse Perl for that. This is
futile with regexes.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Thu, 20 Mar 2003 08:08:03 +0100
From: =?ISO-8859-15?Q?S=E9bastien?= Cottalorda <spp@monaco377.com>
Subject: Re: Socket Problem In Perl
Message-Id: <3e7968da$0$30757$626a54ce@news.free.fr>

Hi,

Ryan Ritten wrote:

> hello,
> 
> I wrote a little client/server in perl using sockets.  Everything
> works fine if the client exits normally ... the server notices that
> the socket is done and closes it.  But if the client dies abnormally
> (ie. computer freezes... etc) the server doesn't notice that the
> client is gone and keeps the socket open...
>

It's true, if your client is frozen, nothing is sent to the server to 
indicate him that the client is out of order.
 
> am I doing something wrong?  Is this was it supposed to happen or is
> there a quick fix for it.  I'd paste my code here but it's part of a
> game I've made and is huge.
> 

I'd try to solve this problem by made the client poll the server every X 
minutes (or seconds).
On the server side, if a certain time elapsed without any reception, I'll 
declare client out of order.
That's not very nice (I know) but may be that could help you. 

> Thanx for any help you can give :)
> 
> -Ryan

Sebastien


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

Date: 19 Mar 2003 21:25:24 -0800
From: dwlepage@yahoo.com (david)
Subject: Text::ParseWords or Text::CSV
Message-Id: <b09a22ae.0303192125.45a94361@posting.google.com>

Does anyone have experience with either of these two modules? Im
trying to figure out how to parse a comma delimited file, but the
problem is certain fields also have commas so when the file is
exported to text format, of course it now looks like it has more
fields. I want to remove the comma's from the fields that have them:

dlepage,engineer,mn,"infrastrucuture",6-5-02
aidan,support,va,"infrastructure,engineering", 3-1-96

I put quotes around the actual 'field 3', but the actual file I want
to work on does NOT have the quotes:

dlepage,engineer,mn,infrastrucuture,6-5-02
aidan,support,va,infrastructure,engineering, 3-1-96

i.e.
field0=aidan
field1=support
field2=va
field3=infrastructure,engineering
field4=3-1-96

So far im stuck on the basics of either of these modules, and first of
all, whether any of these are the right ones to use.
perl -w
use strict;
use Text::ParseWords
open (IN, "<infile.txt") || die "Cannot open $!\n";

my $line;
while ($line = <IN> ) {
         @words = &parse_line(/,/, 0, $line);
         print $line
 }

This is very simplified code because I could not get any variations on
this theme to work.
I think if possible, I should be parsing by comma's up to and
including 0-2 and take whatever is in field 3 and remove the comma if
present. Any suggestions?

Thanks,


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

Date: Thu, 20 Mar 2003 07:37:51 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: Text::ParseWords or Text::CSV
Message-Id: <pan.2003.03.20.06.37.23.135636@aursand.no>

On Wed, 19 Mar 2003 21:25:24 -0800, david wrote:
> dlepage,engineer,mn,"infrastrucuture",6-5-02
> aidan,support,va,"infrastructure,engineering", 3-1-96
> 
> I put quotes around the actual 'field 3', but the actual file I want to
> work on does NOT have the quotes:
> 
> dlepage,engineer,mn,infrastrucuture,6-5-02
> aidan,support,va,infrastructure,engineering, 3-1-96

If you are _sure_ that the three first, together with the last, column(s)
won't contain any commas, I really don't see the problem?

The easiest (?) solution I see, from the top of my tired head;

  m/^(.*?),(.*?),(.*?),(.*),(.*)$/

Or?


-- 
Tore Aursand


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

Date: 19 Mar 2003 22:13:46 -0800
From: carltonbrown@hotmail.com (Carlton Brown)
Subject: Re: Why is alarm() waiting for inconsistent periods of time?
Message-Id: <aa611a32.0303192213.3909dc99@posting.google.com>

Big and Blue <No_4@dsl.pipex.com> wrote in message news:<3e78d65e$0$4849
>    It is possible that time is being kept in check on your system by NTP 
> (or similar).  This will be adjusting the clock from time to time.  Your 
> alarm() call will still arrive after 3 hours as far as the processors 
> are concerned, but in the meantime a few seconds have been removed from 
> the wall clock?

A reasonable theory, but is it really likely that the system time is
losing one second per hour relative to the time server?

>     Anyway, you are using it to timestamp/keepalive.  It shouldn't 
> matter to the effect you are trying to achieve.

True, I just hoped to understand the behavior... if I ever depended on
it being accurate, it seems that alarm() wouldn't be reliable, unless
I am missing something.


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

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


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