[24788] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6941 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 1 09:06:16 2004

Date: Wed, 1 Sep 2004 06: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)

Perl-Users Digest           Wed, 1 Sep 2004     Volume: 10 Number: 6941

Today's topics:
    Re: carp() /  STDERR <r.mcglue@qub.ac.uk>
        Complex Records help (Traveller2003)
    Re: Complex Records help <josef.moellers@fujitsu-siemens.com>
    Re: Complex Records help <xx087@freenet.carleton.ca>
    Re: Complex Records help <tore@aursand.no>
    Re: Fastest versions of perl? <skweek@no.spam>
    Re: Fastest versions of perl? <stephen@jadevine.org.uk>
    Re: Formmail.pl - Sendmail vs. Smtp chris-usenet@roaima.co.uk
    Re: Help: Open an URL an keep reading from it, non-bloc gisle@activestate.com
        Lwp Post Problem (Sure)
    Re: Lwp Post Problem <noreply@gunnar.cc>
    Re: mod_perl on apache 1.3 and 2.0 performance test, ol <tore@aursand.no>
        Newbie: Win32:Sound:WaveOut problem <invalid@invalid.invalid>
    Re: perl pattern matching <nobull@mail.com>
        PERL5LIB - @INC - machine dependant subdirs <koos@no.spam>
    Re: Reading UTF-8 string from file with read() function <nobull@mail.com>
    Re: share winlyrics to wmp SMI in perl (Anno Siegel)
    Re: unexpected EXTENDED_OS_ERROR on Windows (Griff)
    Re: Xah Lee's Unixism <mru@mru.ath.cx>
    Re: Xah Lee's Unixism <steveo@eircom.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 01 Sep 2004 09:18:30 +0100
From: R McGlue <r.mcglue@qub.ac.uk>
Subject: Re: carp() /  STDERR
Message-Id: <ch40kk$1cm$1@news.qub.ac.uk>

Paul Lalli wrote:
> "R McGlue" <r.mcglue@qub.ac.uk> wrote in message
> news:ch21u2$omd$1@news.qub.ac.uk...
> 
>>Paul Lalli wrote:
>>
>>
>>>my $logfile = '/home/errs.txt';
>>>open STDERR, '>>', $logfile or die "Could not redirect STDERR: $!";
>>>
>>>(Note: Perl is smart enough to not lose track of the original STDERR
> 
> if
> 
>>>the open fails here, so the die message will still be printed to
>>>wherever STDERR is pointing if $logfile cannot be opened for
> 
> appending.)
> 
>>so if carp was to return and error message it would get written to
>>/home/errs.txt
>>?
> 
> 
> Any message printed to STDERR, including those printed by carp(), would
> be printed to whatever file you named in $logfile (/home/errs.txt in
> this case), yes.
> 
> Paul Lalli
> 
> 
Right I'll elaborate a little more... I need to close STDERR if possible 
as the script spawns multiple clients and servers which communicate with 
each other via FIFO pipes. Its a fudged bit of code... but it works. I 
need to close STDERR to minimise disk leakage. Aside from opening STDERR 
and closing it around a carp or die command is there anyother way this 
can be implemted more..... 'cleanly'

Ronan


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

Date: 1 Sep 2004 03:47:58 -0700
From: vavavoom_th14@yahoo.co.uk (Traveller2003)
Subject: Complex Records help
Message-Id: <6e21e513.0409010247.a080e9f@posting.google.com>

Hi All , 

I am a bit stuck. I have only recently started using perl and trying
to get to grips with the references , scalar and list contexts. I
realise if I can understand these and spot them than I am on my way to
learning perl.

The following is the script I am using and need help as to what I am
doing wrong or better still a perl way of writing it.

I have defined a Record sturcture and would like to use it through my
whole program. As such I am getting all the details I require into the
record structure "UserInfoRec".

 
#!/usr/bin/perl -w

##### User Info Structure #######
$UserInfoRec = {
    PASSWDINFO => { LOGINNAME => "",
                    PASSWORD => "",
                    USERID => "",
                    USERGRP => "",
                    RESERVED => "",
                    WORKINGDIR=> "",
                    SHELL => "" },
    DATABASEINFO   => {%DBEnv}
}; # End user record

######################################################################################
# sets up the Var used within program.
######################################################################################
sub setenv {


open(PASSWD,"/etc/passwd") or die "Cannot read passwd file ? ($?)";

$UserInfoRec = () ;  # Initialise the Record 
    while (<PASSWD>) {
        chomp;
        if (/^root:/) { # Found  root entry user entry
            @UserInfo = split(/\:/,$_);
            $counter=0;

           print $UserInfoRec{PASSWDINFO};

==============>   My comment    <===============
Never enters the while loop. I have a feeling I am looking at the
reference as opposed to what I really want to get. i.e LOGINNAME,
PASSWORD etc. I want to populate the values in the while loop but not
sure how to do it.
==============> End my Comment  <=============== 
 
           while ( ($param ) = each %{$UserInfoRec{PASSWDINFO} } ) {
               print "PARAM = $param \n";
               $UserInfoRec{PASSWDINFO}{$param}= $UserInfo[$counter];
               ++$counter;
               print "Counter = $counter  param = $param \n";
           } # While each
        } # End if

    } # End While


    while ( ( $pwinfo ) = each %{$UserInfoRec{PASSWDINFO}} ) {
        print "$pwinfo = $UserInfoRec{PASSWDINFO}{$pwinfo} \n";
    }

}   #=======(End setenv)=======#




TIA. 

Traveller2003.


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

Date: Wed, 01 Sep 2004 13:29:58 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Complex Records help
Message-Id: <ch4bkh$1h8$1@nntp.fujitsu-siemens.com>

Traveller2003 wrote:

> #!/usr/bin/perl -w
>=20
> ##### User Info Structure #######
> $UserInfoRec =3D {

You define a reference to an anonymous hash ...

>            print $UserInfoRec{PASSWDINFO};

You reference the PASSWDINFO of the (non-existent) hash %UserInfoRec.

Since $UserInfoRec is a reference, use $UserInfoRec->{PASSWDINFO} to=20
access the PASSWDINFO field.

There's probably more, but as I've just BTDT ...

Josef
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett



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

Date: 1 Sep 2004 12:12:21 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: Complex Records help
Message-Id: <slrncjbf55.5u1.xx087@smeagol.ncf.ca>

At 2004-09-01 06:47AM, Traveller2003 <vavavoom_th14@yahoo.co.uk> wrote:
>  Hi All , 
>  
>  I am a bit stuck. I have only recently started using perl and trying
>  to get to grips with the references , scalar and list contexts. I
>  realise if I can understand these and spot them than I am on my way to
>  learning perl.

In 'perldoc perlref', refer to #3 of section "Making References", and the
section "Using References", or get the "Programming Perl" book.  Or both.

[...]
>  $UserInfoRec = {
>      PASSWDINFO => { LOGINNAME => "",
[...]
>  }; # End user record

Now, $UserInfoRec is a reference to a hash


>  sub setenv {
>  $UserInfoRec = () ;  # Initialise the Record 

Now, $UserInfoRec is undefined.

>      while (<PASSWD>) {
[...]
>             print $UserInfoRec{PASSWDINFO};

As mentioned earlier, the hash variable %UserInfoRec does not exist.

> ==============>   My comment    <===============
>  Never enters the while loop. I have a feeling I am looking at the
>  reference as opposed to what I really want to get. i.e LOGINNAME,
>  PASSWORD etc. I want to populate the values in the while loop but not
>  sure how to do it.
> ==============> End my Comment  <=============== 
>   
>             while ( ($param ) = each %{$UserInfoRec{PASSWDINFO} } ) {

See 'perldoc -f each' and 'perldoc -f keys'



-- 
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca


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

Date: Wed, 01 Sep 2004 14:21:15 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Complex Records help
Message-Id: <pan.2004.09.01.12.21.14.42356@aursand.no>

On Wed, 01 Sep 2004 03:47:58 -0700, Traveller2003 wrote:
> #!/usr/bin/perl -w

Use this instead:

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

> ##### User Info Structure #######
> $UserInfoRec = {
>     PASSWDINFO => { LOGINNAME => "",
>                     PASSWORD => "",
>                     USERID => "",
>                     USERGRP => "",
>                     RESERVED => "",
>                     WORKINGDIR=> "",
>                     SHELL => "" },
>     DATABASEINFO   => {%DBEnv}
> }; # End user record

Here you define a hash reference.  You might want to use single quotes
instead of double quotes, and you might want to reference to %DBEnv;

  my $UserInfoRec = {
      PASSWDINFO   => {
          LOGINNAME  => '',
          PASSWORD   => '',
          USERID     => '',
          USERGRP    => '',
          RESERVED   => '',
          WORKINGDIR => '',
          SHELL      => '',
      },
      DATABASEINFO => \%DBEnv,
  }

> open(PASSWD,"/etc/passwd") or die "Cannot read passwd file ? ($?)";

Needless use of double quotes (again), and why do you use the '$?'
variable?

  open( PASSWD, '/etc/passwd' ) or die "Cannot read passwd file; $!\n";

> $UserInfoRec = () ;  # Initialise the Record 

Again?  Or do you want to have a record local to the current subroutine? 
If so, you could do this;

  local $UserInfoRec = {};

I would, however, use a different name for it.  Makes your code a bit
easier to read, IMO.

>            print $UserInfoRec{PASSWDINFO};

$UserInfoRec is a hash _reference_, so you have to treat it like that, not
as a normal hash;

  print $UserInfoRec->{PASSWDINFO};

>            while ( ($param ) = each %{$UserInfoRec{PASSWDINFO} } ) {
>                print "PARAM = $param \n";
>                $UserInfoRec{PASSWDINFO}{$param}= $UserInfo[$counter];
>                ++$counter;
>                print "Counter = $counter  param = $param \n";
>            } # While each

First of all, 'each' always returns two elements (ie. the key/value pair
from the hash).  See 'perldoc -f each' for more information.

In this context, however, I think you want to extract only the keys from
the hash reference, right?

Secondly, you're still not treating your hash reference for what it is; a
hash reference;

  foreach my $param ( keys %{$UserInfoRec->{PASSWDINFO}} ) {
      $UserInfoRec->{PASSWDINFO}->{$param} = $UserInfo[$counter];
      $counter++;
      print "COUNTER = $counter / PARAM = $param\n";
  }


>     while ( ( $pwinfo ) = each %{$UserInfoRec{PASSWDINFO}} ) {
>         print "$pwinfo = $UserInfoRec{PASSWDINFO}{$pwinfo} \n";
>     }

Once again, I don't think that 'each' will do you what you expect here;

  foreach my $pwinfo ( keys %{$UserInfoRec->{PASSWDINFO}} ) {
      print "$pwinfo = " . $UserInfoRec->{PASSWDINFO}->{$pwinfo} . "\n";
  }


-- 
Tore Aursand <tore@aursand.no>
"Life is pleasant. Death is peaceful. It's the transition that's
 troublesome." (Isaac Asimov)


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

Date: Wed, 01 Sep 2004 09:13:46 +0200
From: AlV <skweek@no.spam>
Subject: Re: Fastest versions of perl?
Message-Id: <413576aa$0$18616$626a14ce@news.free.fr>

Pablo S wrote:
> Hi, 
> 
> Check this paradox -
> 
> Run from bash on 2 redhat systems with the same hardware:
> 
> #!/usr/bin/perl 
> $start=time;
> my $i=20000000;
> 
> while ($i) {
>     $i--;
> }
> print "Finished!". (time - $start);
> 
> 
> Stock redhat 7.3: 3 seconds (5.6.1)
> Stock FC2: 37 seconds (5.8.3)

Well, I tested your program with my different perl installations 
(compiled by myself for different purposes):
	Perl 5.6.1 : 4 seconds
	Perl 5.8.0 : 4 seconds
	Perl 5.8.4 : 4 seconds

My guess is either 5.8.3 was severely broken in case you should upgrade 
or the soooo clever people at Fedora/Red Hat screwed something ;o)

My advice is that you should compile by yourself a perl 5.8.* source 
archive taken from your local CPAN mirror and see what is how it behaves.

Have a nice day,


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

Date: Wed, 01 Sep 2004 08:43:57 +0100
From: Stephen Quinney <stephen@jadevine.org.uk>
Subject: Re: Fastest versions of perl?
Message-Id: <87r7pm4eo2.fsf@mizar.oucs.ox.ac.uk>

AlV <skweek@no.spam> writes:

> Pablo S wrote:
>> Hi, Check this paradox -
>> Run from bash on 2 redhat systems with the same hardware:
>> #!/usr/bin/perl $start=time;
>> my $i=20000000;
>> while ($i) {
>>     $i--;
>> }
>> print "Finished!". (time - $start);
>> Stock redhat 7.3: 3 seconds (5.6.1)
>> Stock FC2: 37 seconds (5.8.3)
>
> Well, I tested your program with my different perl installations
> (compiled by myself for different purposes):
> 	Perl 5.6.1 : 4 seconds
> 	Perl 5.8.0 : 4 seconds
> 	Perl 5.8.4 : 4 seconds
>
> My guess is either 5.8.3 was severely broken in case you should
> upgrade or the soooo clever people at Fedora/Red Hat screwed something
> ;o)

Does that FC2 have SELinux turned on, in either mode? If so, that
might slow things down a bit. It'd be interesting to see the breakdown
of the total time into compile time and run time that might tell you
where the real problem lies. Do other things on the FC2 box run slowly
compared to the RH7.3 box?  If so, I'd expect you've got a hardware
problem somewhere.

Stephen



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

Date: Wed, 1 Sep 2004 09:08:40 +0100
From: chris-usenet@roaima.co.uk
Subject: Re: Formmail.pl - Sendmail vs. Smtp
Message-Id: <8lcg02-dle.ln1@moldev.cmagroup.co.uk>

Chris <ceo@nospan.on.net> wrote:
> If these are really your friends, and you are really trying to help 
> them, then DON'T use formmail.pl to process their mail.  Just DON'T. 
> Especially if it's Matt Wright's formmail.pl.

> Write a real (secure) script that uses Net::SMTP or the many other variants.

If they don't know (or understand) what's wrong with formmail.pl then
the chances are that if they roll their own, they'll repeat all the
mistakes anyway. Use the nms scripts at sourceforge instead.

Chris


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

Date: 01 Sep 2004 14:38:12 +0200
From: gisle@activestate.com
Subject: Re: Help: Open an URL an keep reading from it, non-blocking
Message-Id: <87eklm9nbf.fsf@ask.i-did-not-set--mail-host-address--so-shoot-me>

John Bokma <postmaster@castleamber.com> writes:

> Is there a way to do this in Perl. I mean, is there a module that let's me 
> see if there is data available, and read it, and move on in a loop?

LWP give you a callback that will be called each time data is received
from the server.  Try something like this:

    $ua = LWP::UserAgent->new;
    $ua->get( $url,
              ':content_cb' => sub {
                  my($data, $response) = @_;
                  print $data;
              })

-- 
Gisle Aas


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

Date: 1 Sep 2004 03:09:40 -0700
From: csuresh01@yahoo.com (Sure)
Subject: Lwp Post Problem
Message-Id: <abb15b21.0409010209.71b849db@posting.google.com>

Hello All,
I want to update a form using the LWP & HTTP method. It was 
working fine when I am updating the values like this 

$ua = LWP::UserAgent->new;
$url ='http://xxx.be/cgi-bin/viewauth/Tracking/TestProjectAgainInitialDevStory#edittable2';
use HTTP::Request::Common;

my $res = $ua->request(POST $url,
  Content_Type =>'form-data',
  Content => [
  ettablenr => '2',
  etcell2x1 =>'Task',
  etcell2x2 =>'2',
  etcell2x3 =>'3',
  etcell2x4 =>'4',
  etcell2x5 =>'High',
  etcell2x6 =>'SureshC',
  etcell2x7 =>'CSuresh',
  etcell2x8 =>'Twiki Data Updation',
  etrows  => '2',
  etsave =>'Save table']);


It was not working when I store the value into a Variable. Like This. 

$postStr =   ettablenr => '2',  etcell2x1 =>'Task',  etcell2x2 =>'2', 
etcell2x3 =>'3',  etcell2x4 =>'4',  etcell2x5 =>'High',  etcell2x6
=>'SureshC',  etcell2x7 =>'CSuresh',  etcell2x8 =>'Twiki Data
Updation',  etrows  => '2',  etsave =>'Save table']);

$ua = LWP::UserAgent->new;
my $res = $ua->request(POST $url,  Content_Type=>'form-data',  Content
=>[$postStr]);

Can any one pls let me know what is the problem when i doing like
this.


Thanks in Advance


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

Date: Wed, 01 Sep 2004 12:43:50 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Lwp Post Problem
Message-Id: <2plnsiFmej57U1@uni-berlin.de>

Sure wrote:
> It was not working when I store the value into a Variable. Like
> This.
> 
> $postStr =   ettablenr => '2',  etcell2x1 =>'Task',  etcell2x2
> =>'2', etcell2x3 =>'3',  etcell2x4 =>'4',  etcell2x5 =>'High',
> etcell2x6 =>'SureshC',  etcell2x7 =>'CSuresh',  etcell2x8 =>'Twiki
> Data Updation',  etrows  => '2',  etsave =>'Save table']);
> 
> $ua = LWP::UserAgent->new;
> my $res = $ua->request(POST $url,  Content_Type=>'form-data',
> Content =>[$postStr]);
------------^--------^

Assuming $postStr is an array reference:

     my $postStr = [ ettablenr => '2', ... etsave =>'Save table' ];

this should work:

     my $res = $ua->request(POST $url,
       Content_Type =>'form-data',
       Content => $postStr);

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Wed, 01 Sep 2004 12:53:35 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: mod_perl on apache 1.3 and 2.0 performance test, old vs new. strage..
Message-Id: <pan.2004.09.01.10.53.34.292113@aursand.no>

On Tue, 31 Aug 2004 22:18:13 -0700, Pablo S wrote:
> [ Bad performance with Apache 2.x over Apache 1.x ]
>
> Is apache the culprit?  I was running all over looking at the database I
> was talking to, etc etc, but heres a simple loop taking about 3x as
> long.

You have to hone your benchmarking skills.  You'll easily find out if one
Apache version is serving slower than another Apache version by simple
running the 'ab' tool on a simple HTML file;

  % /usr/local/apache/bin/ab -n 100000 -k -c 4 http://localhost/test.html

'test.html' should - of course - not contain very much.  Just some simple
HTML markup with no outside references (ie. images, CSS files, etc.)

Moving on to the next step:  Create a simple script like this:

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

  my $i = 100_000_000;
  while ( $i > 0 ) {
      $i--;
  }

Run this script with each of the Perl versions you have.  Something tells
me that this really is a Perl issue, but that your fastest Perl version is
compiled differently than that slower Perl version.

I experienced the same thing when upgrading from Perl 5.6.0 to Perl 5.6.1;
The former was installed as plain RPM with all the fance stuff included,
while the latter was compiled specifically for the computer I was running
at that time, with just the necessary stuff enabled.

The result:  Perl 5.6.1 was _a lot_ faster than the previous version, and
I could easily benchmark that from a simple "routine" as the one above.

I'll be happy to see your benchmark results!


-- 
Tore Aursand <tore@aursand.no>
"Why shouldn't truth be stranger than fiction? Fiction, after all, has
 to make sense." (Mark Twain)


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

Date: Wed, 01 Sep 2004 11:05:03 GMT
From: "DG" <invalid@invalid.invalid>
Subject: Newbie: Win32:Sound:WaveOut problem
Message-Id: <z1iZc.96511$Fg5.43900@attbi_s53>

Hello and thanks for the help,

 I would like to play a *portion* of a wav file (say from sample 400 to
sample 9000) on a Windows machine.
 Unfortunately, I'm unable to get my code to work.  Below are my tests.

 I tried the following code:

   use Win32::Sound;
   $WAV = new Win32::Sound::WaveOut("klaxton.wav"); #open "klaxton.wav"
located in the current directory
   $WAV->Play(400,9000);                            #play from sample 400 to
sample 9000


 When I run it, I get the following error messages:
   Use of uninitialized value at C:/Perl/site/lib/Win32/Sound.pm line 109.
   Argument "klaxton.wav" isn't numeric in entersub at
C:/Perl/site/lib/Win32/Sound.pm line 109.


 So I tried the modified code below:

   use Win32::Sound;
   $WAV = new Win32::Sound::WaveOut(); #use defaults
   $WAV->Open("klaxton.wav");          #open "klaxton.wav" located in the
current directory
   $WAV->Play(400,9000);               #play from sample 400 to sample 9000

 When I run it, I get the following error messages:
   Use of uninitialized value at C:/Perl/site/lib/Win32/Sound.pm line 109.
   Use of uninitialized value at C:/Perl/site/lib/Win32/Sound.pm line 109.
   Use of uninitialized value at C:/Perl/site/lib/Win32/Sound.pm line 109.
   Use of uninitialized value at x.bat line 28.
   Argument "klaxton.wav" isn't numeric in entersub at x.bat line 28.


 To test the Sound package, I ran the following code (it worked fine):
   use Win32::Sound;
   Win32::Sound::Play("klaxton.wav");


 To test the WaveOut package, I ran the example code given in the
documentation (shown below).  It worked fine.


   use Win32::Sound;

   # Create the object
   $WAV = new Win32::Sound::WaveOut(44100, 8, 2);

   $data = "";
   $counter = 0;
   $increment = 440/44100;

   # Generate 44100 samples ( = 1 second)
   for $i (1..44100) {

       # Calculate the pitch
       # (range 0..255 for 8 bits)
       $v = sin($counter/2*3.14) * 128 + 128;

       # "pack" it twice for left and right
       $data .= pack("cc", $v, $v);

       $counter += $increment;
   }

   $WAV->Load($data);       # get it
   $WAV->Write();           # hear it
   1 until $WAV->Status();  # wait for completion
   $WAV->Save("sinus.wav"); # write to disk
   $WAV->Unload();          # drop it


 So the packages are working.  The wav file is present.  Yet I can't get my
original code to work.  What am I doing wrong?

thanks for the help,
DG




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

Date: Wed, 01 Sep 2004 08:57:18 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: perl pattern matching
Message-Id: <ch3v4k$619$1@sun3.bham.ac.uk>


Niko top-posts:

[ please don't top-post ]

 > "J. Gleixner" <glex_nospam@qwest.invalid> wrote in message 
news:<m81Zc.10$Iv3.18891@news.uswest.net>...
 >
 >>Niko wrote:
 >>
 >>>i need help replacing string in the middle of line like this :
 >>>
 >>>var1:string:yyy:zzz:kkk.....:ggg
 >>>
 >>
 >>I'm guessing you want to replace 'string', in your example line above,
 >>with another value and you know the beginning of the line you want to
 >>replace, which in this case is 'var1'.
 >>
 >>my $str = 'var1:string:abcd:edfg';
 >>my $beg = 'var1';
 >>my $new_string = 'new_value1';
 >>
 >>$str =~ s/^$beg:([^:]*)/$beg:$new_string/;
 >
> for now this was my code :
> 
> ###  Find and replace strings in a file
> sub Find_Rep { 
>    my $PAT_TXT = $_[0];

It is more ideomatic (and faster) to say:

     my $PAT_TXT = shift;

or

     my ($PAT_TXT) = @_;

>    open (FILE,$S_FILE); 
>    open (TEMPF,"> $T_FILE");

You should always, yes always, check the return value from open().  In 
quick-and-dirty program it is sufficient to append "or die $!".

You should generally avoid using shared variables to pass arguments to 
subrouitnes unless there is a special reason why it's justified.

If you use a bare file handle, FILE, in a subroutine you should use 
local(*FILE).  Better would be to use lexical file handles (unless you 
need compatability with old Perls).

>       while (<FILE>) {
>          eval $PAT_TXT;

You should usually check the value of $@ after eval.  If you can't think 
of something more appropriate just re-throw with:

   die $@ if $@;

But you shouldn't be using eval at all anyhow - you should be calling a 
precomplied code entity - see below.

>          print TEMPF $_;
>          <STDIN>;
>       }
>    close (TEMPF);
>    close (FILE);


I think you have a missing closing curly.

> ####
> $S_FILE="source file";
> $T_FILE="target file";
> $str1="var1";
> str2="var2";

This is an error.

> 
> my $PAT_ST = 's/^$str1:([^:]*)/$str1:$str2/';
>      Find_Rep($PAT_ST);

You should use the natural representation for things (i.e. use a CODE 
entity not a string for holding code).

You should use the natural name for things (i.e. don't use 'PAT' for the 
name of a variable containing a substition command).

The capture brackets are redunant.

It would be a good idea to habitually put tThe $str1 on the LHS of the 
s/// in \Q\E just in case it ever contains RE-special punctuation.

It would be more conventional to preserve the unchanged bit using a 
capture rather the repeat it on each side of the s///.

my $substitution = sub { s/^(\Q$str1\E:)[^:]*/$1$str2/ };



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

Date: Wed, 01 Sep 2004 10:02:51 +0200
From: Koos Pol <koos@no.spam>
Subject: PERL5LIB - @INC - machine dependant subdirs
Message-Id: <newscache$virc3i$et5$1@news.emea.compuware.com>

Hello all,

Is there a common way to construe the machine/architecture
dependent subdirectries below a lib dir and have them added to
@INC?


Background:
I want to keep a local DBI and DBD with my application. When
building the Msql-Mysql-modules it says:

"Using DBI 1.32 installed
in /usr/lib/perl5/site_perl/5.8.0/i586-linux-thread-multi/auto/DBI"

This message in spewed
by /usr/lib/perl5/site_perl/5.8.0/i586-linux-thread-multi/DBI/DBD.pm
Now to find modules DBD simply greps @INC (which only includes my
local lib dir /home/koos/my_perl_app/lib (set by PERL5LIB) and
not the machine dependent subdirs below it. Therefor it doesn't
see my local DBI installed in the machine dependent subdirs
below /home/koos/my_perl_app/lib

Is there any way to construe and add these machine dependent
subdirs to @INC without hacking the DBD code?

Thanks,
Koos

-- 
KP
43rd Law of Computing: "Anything that can go wr
fortune: Segmentation violation -- Core dumped


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

Date: Wed, 01 Sep 2004 09:11:47 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Reading UTF-8 string from file with read() function.
Message-Id: <ch4006$6af$1@sun3.bham.ac.uk>

dr@dark.com wrote:

>>Read the string from file as binary and then utf8::decode() it.
> 
> And where would one go to find utf8::decode?

The function utf8::decode() is documented in the utf8 module that is a 
standard part of the Perl distribution.

It's not really in the module at all but is actually a builtin so you 
don't need to 'use utf8' to use the utf8::decode() function.

> I am on page 22 of CPAN and still haven't found it. 

When I did a seach for utf8::decode on CPAN the utf8 module was the 
third hit.



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

Date: 1 Sep 2004 09:40:03 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: share winlyrics to wmp SMI in perl
Message-Id: <ch45dj$7dn$1@mamenchi.zrz.TU-Berlin.DE>

lechee <lecheel@yahoo.com> wrote in comp.lang.perl.misc:
> #!/usr/bin/perl

[150 lines of undocumented code of dubious quality snipped]

The place to share Perl code is the CPAN, not Usenet.

Anno


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

Date: 1 Sep 2004 03:25:37 -0700
From: griffph@aol.com (Griff)
Subject: Re: unexpected EXTENDED_OS_ERROR on Windows
Message-Id: <d698d3e7.0409010225.39085c2b@posting.google.com>

Thanks everyone. In future I shall check the return value from system
before going into the detail of $^E.


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

Date: Wed, 01 Sep 2004 10:24:10 +0200
From: =?iso-8859-1?q?M=E5ns_Rullg=E5rd?= <mru@mru.ath.cx>
Subject: Re: Xah Lee's Unixism
Message-Id: <yw1xeklm4ct1.fsf@mru.ath.cx>

arargh407NOSPAM@NOW.AT.arargh.com writes:

> On Tue, 31 Aug 2004 17:43:34 GMT, red floyd <no.spam@here.dude> wrote:
>
>>CBFalconer wrote:
>>
>>> Dump Notepad and get Textpad.  www.textpad.com.  First class.
>>> 
>>
>>Let the editor flame wars begin!
>>
>>Get gvim!  www.vim.org
>
> WordPerfect PE or later ED.  No longer sold, AFAIK.

Office68.  Look for an LPROM on ebay.

-- 
Måns Rullgård
mru@mru.ath.cx


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

Date: Wed, 1 Sep 2004 08:40:05 +0100
From: Steve O'Hara-Smith <steveo@eircom.net>
Subject: Re: Xah Lee's Unixism
Message-Id: <20040901084005.3f607995.steveo@eircom.net>

On Tue, 31 Aug 2004 17:43:34 GMT
red floyd <no.spam@here.dude> wrote:

> CBFalconer wrote:
> 
> > Dump Notepad and get Textpad.  www.textpad.com.  First class.
> > 
> 
> Let the editor flame wars begin!
> 
> Get gvim!  www.vim.org

	Wordstar 3.3 of course.

-- 
C:>WIN                                      |   Directable Mirror Arrays
The computer obeys and wins.                | A better way to focus the sun
You lose and Bill collects.                 |    licences available see
                                            |    http://www.sohara.org/


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

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 V10 Issue 6941
***************************************


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