[30094] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1337 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 6 11:09:42 2008

Date: Thu, 6 Mar 2008 08:09:08 -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, 6 Mar 2008     Volume: 11 Number: 1337

Today's topics:
        ANN: Text-CSV_XS 0.36 <h.merijn@xs4all.nl>
        Conditional compilation <jeroen.lodewijks@gmail.com>
    Re: Conditional compilation <devnull4711@web.de>
    Re: Conditional compilation <ben@morrow.me.uk>
        graphic library GD <rose@russ.org>
    Re: graphic library GD <devnull4711@web.de>
    Re: graphic library GD <rose@russ.org>
    Re: graphic library GD <devnull4711@web.de>
    Re: insert codes dynamically <rose@russ.org>
    Re: insert codes dynamically <devnull4711@web.de>
    Re: insert codes dynamically <rose@russ.org>
    Re: insert codes dynamically <devnull4711@web.de>
    Re: insert codes dynamically <ben@morrow.me.uk>
    Re: insert codes dynamically <cartercc@gmail.com>
    Re: insert codes dynamically <ben@morrow.me.uk>
        Notes on unicode/utf8, CGI, DBI, mysql <kalle.bingel@gmail.com>
    Re: Parsing blocks of text in Perl <mgjv@tradingpost.com.au>
        Perl functions (SE)
    Re: Perl functions <michaelgang@gmail.com>
    Re: Perl functions <devnull4711@web.de>
    Re: Rename File Using Strring Found in File? <tadmc@seesig.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 6 Mar 2008 08:07:45 GMT
From: "H.Merijn" <h.merijn@xs4all.nl>
Subject: ANN: Text-CSV_XS 0.36
Message-Id: <JxBDxJ.1Dt@zorch.sf-bay.org>

  file: $CPAN/authors/id/H/HM/HMBRAND/Text-CSV_XS-0.36.tgz
  size: 81490 bytes
   md5: 22f38237fb6c52f283575f9549900509

Request entered by: HMBRAND (H.Merijn Brand)
Request entered on: Thu, 06 Mar 2008 07:54:29 GMT
Request completed:  Thu, 06 Mar 2008 07:55:41 GMT

I finally scratched a longstanding personal itch. No more need for 'use
IO::Handle;'.
Text::CSV_XS will now do that for you automatically at the moment it is
needed, and
only once, so no performance penalty. This will simplify one-liners.

2008-03-06  0.36 - H.Merijn Brand   <h.m.brand@xs4all.nl>

        * Updated ppport.h
        * auto-load IO::Handle when needed
        * Tested with all available perl builds, including a fresh
          threaded 5.11 (blead)

2008-03-01  0.35 (Valloire) - H.Merijn Brand   <h.m.brand@xs4all.nl>

        * use warnings/$^W = 1
        * Tested on 5.10.0, 5.8.8, 5.6.2, and 5.005_04, Strawberry and  Cygwin
        * Diagnostics for failed new ()
        * New 'blank_is_undef' option
        * Updated docs
        * Extended the DIAGNOSTICS a bit
        * Updated TODO
        * Fixed allow_whitespace issue, revealed by blank_is_undef
        * Re-enabled some tests
        * Fixed parse error that passed for q{1, "bar",2} with escape_char  +
        * Reversed an erroneous test result in the funny combo section
        * Extended diagnostics tests
        * Extended XS coverage
        * Removed error 2033

Enjoy, Have FUN! H.Merijn




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

Date: Thu, 6 Mar 2008 06:57:06 -0800 (PST)
From: Wcool <jeroen.lodewijks@gmail.com>
Subject: Conditional compilation
Message-Id: <c9e82e24-fef3-4baf-9f6c-326cf07faec7@47g2000hsb.googlegroups.com>

Hi,

From the chapter on internal workings of Perl in the Perl book, I
think it should be possible to conditionally compile something based
on a variable.

I have the following real problem: my code has a lot of statements
that conditionally print a tracing message.
That is based on a command line parameter.

Is it possible during the compilation phase to NOT generate any code
for those statements if that command line is not set.
Example:


sub Trace
{
    my ($debug, $msg) = @_;

    if ($debug) {
        print $msg."\n";
    }
}

sub SomeFunc1
{
    Trace($opt_d, 'In SomeFunc1');

    ....


    Trace($opt_d, . 'some_var  = '.$var1);

    ...

    Trace($opt_d, . 'some_var2  = '.$var2);

    etc
}

If opt_d is not set I like the Perl not to generate any code for it
internally (some sort of skip)
The compiler would go through SomeFunc1 at just don't parse the Trace
statement.
This would increase speed of the program (slightly).

Is this possible?

Thanks,

Jeroen


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

Date: Thu, 06 Mar 2008 16:37:19 +0100
From: Frank Seitz <devnull4711@web.de>
Subject: Re: Conditional compilation
Message-Id: <63ahdgF26uj5bU6@mid.individual.net>

Wcool wrote:

> Is this possible?

Yes, with a source filter.

$ perldoc perlfilter
Section: USING CONTEXT: THE DEBUG FILTER

Frank
-- 
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel


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

Date: Thu, 6 Mar 2008 15:40:26 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Conditional compilation
Message-Id: <asf5a5-6ic.ln1@osiris.mauzo.dyndns.org>


Quoth Wcool <jeroen.lodewijks@gmail.com>:
> 
> From the chapter on internal workings of Perl in the Perl book, I
> think it should be possible to conditionally compile something based
> on a variable.
> 
> I have the following real problem: my code has a lot of statements
> that conditionally print a tracing message.
> That is based on a command line parameter.
> 
> Is it possible during the compilation phase to NOT generate any code
> for those statements if that command line is not set.
> Example:
> 
> 
> sub Trace
> {
>     my ($debug, $msg) = @_;
> 
>     if ($debug) {
>         print $msg."\n";
>     }
> }
> 
> sub SomeFunc1
> {
>     Trace($opt_d, 'In SomeFunc1');
> 
>     ....
> 
> 
>     Trace($opt_d, . 'some_var  = '.$var1);
> 
>     ...
> 
>     Trace($opt_d, . 'some_var2  = '.$var2);
> 
>     etc
> }
> 
> If opt_d is not set I like the Perl not to generate any code for it
> internally (some sort of skip)
> The compiler would go through SomeFunc1 at just don't parse the Trace
> statement.
> This would increase speed of the program (slightly).

The closest to what you are asking for (without getting into seriously
difficult stuff) is to something like this:

    use constant DEBUG => $opt_d;

    use Carp;

    sub Trace {
        my ($msg) = @_;
        carp $msg;      # carp will send the message to STDERR, and
                        # report it from the point of view of your
                        # caller.
    }

    sub SomeFunc1 {
        Trace('in SomeFunc1') if DEBUG;
    }

Perl will optimize out the Trace calls at compile time, since the
condition is a compile-time constant.

HOWEVER, there is a problem here: the value of $opt_d has to be known at
compile time. This means that your getopt call (or whatever) will have
to be in a BEGIN block.

Also note that the $opt_x interface to Getopt::Std (assuming that's what
you're using) is a bad idea. It's much better to pass getopt a hash to
put the options in.

Ben



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

Date: Thu, 6 Mar 2008 19:34:48 +0800
From: "Rose" <rose@russ.org>
Subject: graphic library GD
Message-Id: <fqokst$bj5$1@ijustice.itsc.cuhk.edu.hk>

Can GD only generate png? Google search returns jpeg generation is possible 
but i cannot obtain its documentation about how to do that. 




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

Date: Thu, 06 Mar 2008 13:02:27 +0100
From: Frank Seitz <devnull4711@web.de>
Subject: Re: graphic library GD
Message-Id: <63a4qkF26uj5bU3@mid.individual.net>

Rose wrote:
> Can GD only generate png? Google search returns jpeg generation is possible 
> but i cannot obtain its documentation about how to do that. 

$ perldoc GD

Method jpeg().

Frank
-- 
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel


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

Date: Thu, 6 Mar 2008 20:43:36 +0800
From: "Rose" <rose@russ.org>
Subject: Re: graphic library GD
Message-Id: <fqooto$d4g$1@ijustice.itsc.cuhk.edu.hk>


"Frank Seitz" <devnull4711@web.de> wrote in message 
news:63a4qkF26uj5bU3@mid.individual.net...
> Rose wrote:
>> Can GD only generate png? Google search returns jpeg generation is 
>> possible
>> but i cannot obtain its documentation about how to do that.
>
> $ perldoc GD
>
> Method jpeg().
>
> Frank
> -- 
> Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
> Anwendungen für Ihr Internet und Intranet
> Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel

Thanks a lot. Mr. Frank Seitz. You are very generous in helping me. ;) 




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

Date: Thu, 06 Mar 2008 13:56:14 +0100
From: Frank Seitz <devnull4711@web.de>
Subject: Re: graphic library GD
Message-Id: <63a7vfF26uj5bU4@mid.individual.net>

Rose wrote:
> 
> Thanks a lot. Mr. Frank Seitz. You are very generous in helping me. ;) 

Pure coincidence :)

Frank
-- 
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel


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

Date: Thu, 6 Mar 2008 16:19:34 +0800
From: "Rose" <rose@russ.org>
Subject: Re: insert codes dynamically
Message-Id: <fqo9en$6o5$1@ijustice.itsc.cuhk.edu.hk>

"Frank Seitz" <devnull4711@web.de> wrote in message 
news:639ejuF26samiU1@mid.individual.net...
> Rose wrote:
>>
>> Frank, Thanks a lot for your response. Indeed, @arr is not known 
>> beforehand
>> and the content of @arr is generated by another perlscript. How would you
>> recommend to bridge these 2 perlscripts? The first one, I store the 10, 
>> 88,
>> ...; 10, 89, ...; and C, T, ... into separate arrays, say @a1, @a2, @a3.
>> A simple but dirty way is to copy the contents of the 1st file to the 2nd 
>> and
>> then @arr = (@a1, @a2, @a3), but this does not look to be a good 
>> practice.
>
> To copy @a1, @a2, @a3 this way would not work.
> Copying is not necessary. Try this:
>
> for (my $i = 0; $i < @a1; $i++) {
>    my $obj = Object::Generic->new(
> -start=>$a1[$i],
> -end=>$a2[$i],
> -display_name=>$a3[$i],
>    );
>    $panel->add_obj($obj);
> }
>
> Frank
> -- 
> Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
> Anwendungen für Ihr Internet und Intranet
> Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel

But can I use a for loop to achieve the following effect? I guess I can't 
simply code:
$panel->add_track([@obj],
    -label       => 1,
);

$panel->add_track([$obj1,$obj2,$obj3, ..., $objn],
    -label       => 1,
);





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

Date: Thu, 06 Mar 2008 10:12:01 +0100
From: Frank Seitz <devnull4711@web.de>
Subject: Re: insert codes dynamically
Message-Id: <639qr2F26uj5bU1@mid.individual.net>

Rose wrote:
> 
> But can I use a for loop to achieve the following effect? I guess I can't 
> simply code:
> $panel->add_track([@obj],
>     -label       => 1,
> );
> 
> $panel->add_track([$obj1,$obj2,$obj3, ..., $objn],
>     -label       => 1,
> );

Can't tell. What expects add_track() as second parameter?
(first parameter is the ref to the panel-Object)

Frank
-- 
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel


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

Date: Thu, 6 Mar 2008 17:39:09 +0800
From: "Rose" <rose@russ.org>
Subject: Re: insert codes dynamically
Message-Id: <fqoe3u$8o8$1@ijustice.itsc.cuhk.edu.hk>


"Frank Seitz" <devnull4711@web.de> wrote in message 
news:639qr2F26uj5bU1@mid.individual.net...
> Rose wrote:
>>
>> But can I use a for loop to achieve the following effect? I guess I can't
>> simply code:
>> $panel->add_track([@obj],
>>     -label       => 1,
>> );
>>
>> $panel->add_track([$obj1,$obj2,$obj3, ..., $objn],
>>     -label       => 1,
>> );
>
> Can't tell. What expects add_track() as second parameter?
> (first parameter is the ref to the panel-Object)
>
> Frank
> -- 
> Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
> Anwendungen für Ihr Internet und Intranet
> Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel

It can accept a number of objects $obj1,$obj2, ..., $objn in square 
brackets. the problem is that "n" is unknown beforehand, and therefore can't 
be hard-coded. I know that in Matlab a function called repmat may help... 




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

Date: Thu, 06 Mar 2008 10:44:15 +0100
From: Frank Seitz <devnull4711@web.de>
Subject: Re: insert codes dynamically
Message-Id: <639sngF26uj5bU2@mid.individual.net>

Rose wrote:
> 
> It can accept a number of objects $obj1,$obj2, ..., $objn in square 
> brackets.

$panel->add_track(\@obj,...);

Frank
-- 
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel


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

Date: Thu, 6 Mar 2008 09:59:07 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: insert codes dynamically
Message-Id: <bsr4a5-l4a.ln1@osiris.mauzo.dyndns.org>

[please don't quote signatures]

Quoth "Rose" <rose@russ.org>:
> "Frank Seitz" <devnull4711@web.de> wrote in message 
> news:639qr2F26uj5bU1@mid.individual.net...
> > Rose wrote:
> >>
> >> But can I use a for loop to achieve the following effect? I guess I can't
> >> simply code:
> >> $panel->add_track([@obj],
> >>     -label       => 1,
> >> );
> >>
> >> $panel->add_track([$obj1,$obj2,$obj3, ..., $objn],
> >>     -label       => 1,
> >> );
> >
> > Can't tell. What expects add_track() as second parameter?
> > (first parameter is the ref to the panel-Object)
> 
> It can accept a number of objects $obj1,$obj2, ..., $objn in square 
> brackets. the problem is that "n" is unknown beforehand, and therefore can't 
> be hard-coded. I know that in Matlab a function called repmat may help... 

If you have an array

    @obj = (1, 2, 3, 4);

then the expression

    [1, 2, 3, 4]

is exactly equivalent to

    [@obj]

 . This is generally true: whenever you have a series of comma-separated
items in list context, you can insert an array into the list and it will
be interpolated. The exception is the argument lists of functions like
'push' which have prototypes and so treat literal arrays specially.

Under many circumstances, it would be better to use

    \@obj

as this doesn't make a copy of the array. You can do this if you know
the function you are calling doesn't modify the passed-in array (or if
you don't care if it trashes @obj).

Note that @obj is *not* equivalent to

    $obj1, $obj2, $obj3, ...

if you were thinking that; $obj[1] is not the same as $obj1. If those
variables weren't just an example, they should have been in an array to
start with.

I would suggest you read perldoc perldsc and perldoc perlreftut.

Ben



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

Date: Thu, 6 Mar 2008 05:30:36 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: insert codes dynamically
Message-Id: <53082d41-f1b6-4300-826b-5a1f14e8b503@13g2000hsb.googlegroups.com>

On Mar 6, 12:16 am, "Rose" <r...@russ.org> wrote:
> "Frank Seitz" <devnull4...@web.de> wrote in message
>
> news:6399lhF2686pmU2@mid.individual.net...
>
>
>
> > Rose wrote:
> >> I have to add objects dynamically in a code and therefore the number of=

> >> objects are not known beforehand. How to achieve this effectly in a
> >> simple
> >> way? e.g.
>
> > my $panel =3D Panel->new(...);
>
> > my @arr =3D ([10,10,'C'],[88,89,'T'],...);
> > for my $e (@arr) {
> >    my $obj =3D Object::Generic->new(
> >        -start=3D>$e->[0],
> >        -end=3D>$e->[1],
> >        -display_name=3D>$e->[2],
> >    );
> >    $panel->add_obj($obj);
> > }
>
> > Frank
> > --
> > Dipl.-Inform. Frank Seitz;http://www.fseitz.de/
> > Anwendungen f=FCr Ihr Internet und Intranet
> > Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
>
> Frank, Thanks a lot for your response. Indeed, @arr is not known beforehan=
d
> and the content of @arr is generated by another perlscript. How would you
> recommend to bridge these 2 perlscripts? The first one, I store the 10, 88=
,
> ...; 10, 89, ...; and C, T, ... into separate arrays, say @a1, @a2, @a3. A=

> simple but dirty way is to copy the contents of the 1st file to the 2nd an=
d
> then @arr =3D (@a1, @a2, @a3), but this does not look to be a good practic=
e.

In the first script, write the array to a text file, values space
separated with each list on a new line, like this:
20 30 A
40 50 B
60 70 C
=2E.. etc

In the second script, read in the file line by line and recreate the
data structure possibly as an array composed of array references.

I assume that you can read and write to a text file in your directory,
and that you will overwrite the same file each day so you can use
static file names.

CC


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

Date: Thu, 6 Mar 2008 15:27:42 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: insert codes dynamically
Message-Id: <e4f5a5-6ic.ln1@osiris.mauzo.dyndns.org>


Quoth "Rose" <rose@russ.org>:
> 
> Frank, Thanks a lot for your response. Indeed, @arr is not known beforehand 
> and the content of @arr is generated by another perlscript. How would you 
> recommend to bridge these 2 perlscripts?

Do they need to be separate scripts? Are they run at different times? If
you are using separate scripts simply as a way of putting the code in
separate files, you may want to use modules instead.

The easy and straightforward way to pass data from Perl to Perl is the
use the Storable module, which is core as of 5.8. In the first script
you say

    use Storable qw/store/;

    store \@arr, 'file' or die "store failed";

and then in the second

    use Storable qw/retrieve/;

    my $aref = retrieve 'file' or die "retrieve failed";

If you want the data to be human-readable, or readable from another
language, you could use YAML instead.

Ben



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

Date: Thu, 6 Mar 2008 02:18:45 -0800 (PST)
From: kbin <kalle.bingel@gmail.com>
Subject: Notes on unicode/utf8, CGI, DBI, mysql
Message-Id: <15f910a2-2302-47ac-adcd-61915ff1fb82@y77g2000hsy.googlegroups.com>


I've written a small tutorial/guide on some of the issues I've come
across when trying to use unicode/utf8 in my LAMP stack and thought
I'd share them.

http://kbinstuff.googlepages.com/perl%2Cunicodeutf8%2Ccgi.pm%2Capache%2Cmod_perla

I hope you will find it useful and please provide me with feedback.

  --Kalle




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

Date: Thu, 6 Mar 2008 22:00:50 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Parsing blocks of text in Perl
Message-Id: <slrnfsvjn2.8gr.mgjv@martien.heliotrope.home>

On Wed, 05 Mar 2008 22:46:00 +0100,
	Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> Martien Verbruggen wrote:
>> Next time, before you post here, show us what you have tried first.
>
> That's good advice.
>
>> This is not a place where you can coe to get free code all the time,
>
> Isn't it? You just made me believe it is. ;-)

Note that I said 'all the time' :)

Martien
-- 
                        | 
Martien Verbruggen      | +++ Out of Cheese Error +++ Reinstall
                        | Universe and Reboot +++
                        | 


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

Date: Thu, 6 Mar 2008 05:31:32 -0800 (PST)
From: "Deepan - M.Sc(SE) - 03MW06" <deepan.17@gmail.com>
Subject: Perl functions
Message-Id: <688a3f1c-1b12-46aa-ae31-432a892b0249@d21g2000prf.googlegroups.com>

Hi all,
     I am using a file  abc.pl which is having a function called
get().

     I am including this perl file inside a cgi script, and also i am
calling this function inside this script. Now this function residing
inside the perl file abc.pl should now look into the URL of the
calling CGI script and it should return the URL for the cgi script.

    Can any of you help me to solve this?

Thanks,
Deepan


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

Date: Thu, 6 Mar 2008 05:56:13 -0800 (PST)
From: david <michaelgang@gmail.com>
Subject: Re: Perl functions
Message-Id: <44b60c58-8945-4971-8522-08fd79e62b39@v3g2000hsc.googlegroups.com>

Hi,

You need to make a package
something like this

abc.pm
package abc;
use strict;
use warnings;

sub get {
}

and then in your script;

use abc;
 .
 .
 .
 .
abc::get(blablabla);

I did not really understand what you want to make but maybe the module
CGI has s function which performs what you need.

Best regards,
David
On Mar 6, 3:31 pm, "Deepan - M.Sc(SE) - 03MW06" <deepan...@gmail.com>
wrote:
> Hi all,
>      I am using a file  abc.pl which is having a function called
> get().
>
>      I am including this perl file inside a cgi script, and also i am
> calling this function inside this script. Now this function residing
> inside the perl file abc.pl should now look into the URL of the
> calling CGI script and it should return the URL for the cgi script.
>
>     Can any of you help me to solve this?
>
> Thanks,
> Deepan



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

Date: Thu, 06 Mar 2008 15:18:07 +0100
From: Frank Seitz <devnull4711@web.de>
Subject: Re: Perl functions
Message-Id: <63acp0F26uj5bU5@mid.individual.net>

Deepan - M.Sc(SE) - 03MW06 wrote:
>
>      I am using a file  abc.pl which is having a function called
> get().
> 
>      I am including this perl file inside a cgi script, and also i am
> calling this function inside this script. Now this function residing
> inside the perl file abc.pl should now look into the URL of the
> calling CGI script and it should return the URL for the cgi script.
> 
>     Can any of you help me to solve this?

use CGI;

sub get {
    return CGI->new->self_url;
}

Frank
-- 
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel


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

Date: Thu, 06 Mar 2008 11:45:38 GMT
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Rename File Using Strring Found in File?
Message-Id: <slrnfsvllv.4a2.tadmc@tadmc30.sbcglobal.net>

He Who Greets With Fire <Entwadumayla@HyenaKiller.com> wrote:
> On Tue, 04 Mar 2008 12:10:16 GMT, Tad J McClellan
><tadmc@seesig.invalid> wrote:
>
>>He Who Greets With Fire <Entwadumayla@HyenaKiller.com> wrote:
>>
>>> I have a file directory named E:/personalinjury. In the file directory
>>> are 821 files named from 1.htm to 821.htm 
>>>
>>> I want to access each file in turn, 
>>
>>
>>    foreach my $file ( glob 'E:/personalinjury/*.htm' ) { # untested
>>
>>
>>> and use a regex to parse the file
>>> contents to see if a string similar to this one is found in it:
>>> Citation: 20-333 Dorsaneo, Texas Litigation Guide § 333.103
>>
>>    open my $PI, '<', $file or die "could not open '$file' $!";
>>    while ( <$PI> ) {
>>       next unless /Citation: [\d-]+.*([\d.]+)/;
>>       my $newfile = $1;
>>
>>
>>> So, I want to rename that file to 333.103 from whatever it was before
>>
>>
>>       rename $file, "$newfile.htm" or die "could not mv '$file' $!";
>>       last;
>>    }
>>    close $PI;
>
>
> I have solved all the problems and have created a working script to
> accomplish the task I needed to do . THere are however some problems
> with the code you posted above here. For one, the rename() function
> takes string values as arguments, not file handles. 


Right.


> A file handle is a
> pointer, 


Wrong.


> and as such, its value is a numerical value representing an
> address in RAM memory, not a string value. The $file variable you used
> above as the first argument to rename() is a file handle, not a string


No, $file is a string, not a filehandle.


> value. Second, you cannot rename a file that is presently open for
> reading. 


Yes I can.


> Above, you closed the file later after you tried to rename
> it. 


Works fine on most sensible filesytems.


> You should have closed it before you tried to rename it.


Not necessary on most sensible filesytems.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V11 Issue 1337
***************************************


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