[25385] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7630 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 11 14:05:50 2005

Date: Tue, 11 Jan 2005 11:05:16 -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           Tue, 11 Jan 2005     Volume: 10 Number: 7630

Today's topics:
    Re: 20050110: string join, substring, length <jgibson@mail.arc.nasa.gov>
    Re: complex numbers (Anno Siegel)
    Re: complex numbers <itsme@yahoo.com>
    Re: complex numbers (Anno Siegel)
        CPAN troubles again (Arkady Zilberberg)
    Re: Extarcting And Storing a String <hx_101@hotmail.com>
    Re: File parsing <news@chaos-net.de>
    Re: File parsing <do-not-use@invalid.net>
    Re: File parsing <tadmc@augustmail.com>
    Re: File parsing <tadmc@augustmail.com>
    Re: File parsing <do-not-use@invalid.net>
    Re: File parsing <news@chaos-net.de>
    Re: File parsing <news@chaos-net.de>
    Re: File parsing <jgibson@mail.arc.nasa.gov>
    Re: GLOB vs IO::Handle xhoster@gmail.com
    Re: GLOB vs IO::Handle (Anno Siegel)
    Re: GLOB vs IO::Handle <nobull@mail.com>
    Re: How to change configuration on installed Perl ? (Anno Siegel)
    Re: How to convert a string "-" to an operator -? <nobull@mail.com>
    Re: How to convert a string "-" to an operator -? <jgibson@mail.arc.nasa.gov>
        Lexical filehandles must be simple scalars (not eg hash <richard@zync.co.uk>
    Re: Lexical filehandles must be simple scalars (not eg  xhoster@gmail.com
    Re: Lexical filehandles must be simple scalars (not eg  (Anno Siegel)
    Re: Lexical filehandles must be simple scalars (not eg  <toddrw69@excite.com>
    Re: portable no warnings "uninitialized" <uffesterner@spamhole.com>
    Re: portable no warnings "uninitialized" <noreply@gunnar.cc>
    Re: portable no warnings "uninitialized" (Peter Scott)
    Re: portable no warnings "uninitialized" <nobull@mail.com>
    Re: system fails <tadmc@augustmail.com>
    Re: system fails (Anno Siegel)
    Re: system fails <a.newmane.remove@eastcoastcz.com>
    Re: system fails <matternc@comcast.net>
    Re: Tk: Call subroutine when MainWindow is realized? <lusol@Dragonfly.cc.lehigh.edu>
    Re: URGENT --- Aspell Scores <tadmc@augustmail.com>
    Re: Writing to Filehandle <tadmc@augustmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 11 Jan 2005 10:04:55 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: 20050110: string join, substring, length
Message-Id: <110120051004558257%jgibson@mail.arc.nasa.gov>

In article <1105427394.732934.140900@f14g2000cwb.googlegroups.com>, Xah
Lee <xah@xahlee.org> wrote:

Please indicate that the following text applies only to Python. You
preface the Perl sections this way, so why not the Python, especially
for those of us who are reading your posts on comp.lang.perl.misc.

 
> # index can be negative,
> # and sometimes out of bound will just mean length of the string
> print a[3:-2]

Please tell those of us who do not know Python what exactly a[3:-2]
means. And why "sometimes"? When does an out-of-bound array index mean
the length of the string and when does it not? You seemed to assume
that your readers all know Python. If that is the case, you should be
posting only to comp.lang.python and not clpm.


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


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

Date: 11 Jan 2005 17:59:17 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: complex numbers
Message-Id: <cs145l$8d6$2@mamenchi.zrz.TU-Berlin.DE>

It's me <itsme@yahoo.com> wrote in comp.lang.perl.misc:

[reply moved to bottom into context]

> "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
> news:Fm6Ed.3556$u47.321@trnddc09...
> > xah@xahlee.org wrote:
> > > #python supports complex numbers.
> > [...]
> >
> > So?
> >
> 
> The world would come to a halt if all of a sudden nobody understands complex
> numbers anymore.  :-)
> 
> > > # Perl doesn't support complex numbers. But there are packages that
> > > supports it.
> >
> > The Math::Complex module is part of the standard installation already, no
> > need for any "packages" (whatever that might be).
> > Did you check "perldoc Math::Complex"
> >
> > NAME
> >     Math::Complex - complex numbers and associated mathematical functions
> > [...]

> For those of us that works with complex numbers, having complex number as a
> natively supported data type is a big advantage.  Non-native add-ons are not
> sufficient and lead to very awkward program code.

Like this?

    use Math::Complex;

    my $z = sqrt( -1);
    print 1 + $z, "\n"; # prints "1+i"

Operator overloading makes it possible to work with complex numbers as if
they were a native data type.

Anno



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

Date: Tue, 11 Jan 2005 18:23:24 GMT
From: "It's me" <itsme@yahoo.com>
Subject: Re: complex numbers
Message-Id: <wQUEd.10284$5R.7006@newssvr21.news.prodigy.com>

Operator overloading (and function overloading) helps but not enough.    You
have to be aware of the complex type *everywhere* you go and that's very
annoying and error prone.  I've been the works with C++, and later with
Modelica.   I am very happy that Python included *native* complex number
support.

I really like Python's notion of having just one data type: the duck.



"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:cs145l$8d6

<snip>

>
> Like this?
>
>     use Math::Complex;
>
>     my $z = sqrt( -1);
>     print 1 + $z, "\n"; # prints "1+i"
>
> Operator overloading makes it possible to work with complex numbers as if
> they were a native data type.
>
> Anno
>




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

Date: 11 Jan 2005 19:00:29 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: complex numbers
Message-Id: <cs17od$ag1$1@mamenchi.zrz.TU-Berlin.DE>

It's me <itsme@yahoo.com> wrote in comp.lang.perl.misc:

[reply moved into context]

> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:cs145l$8d6
> 
> <snip>
> 
> >
> > Like this?
> >
> >     use Math::Complex;
> >
> >     my $z = sqrt( -1);
> >     print 1 + $z, "\n"; # prints "1+i"
> >
> > Operator overloading makes it possible to work with complex numbers as if
> > they were a native data type.

> Operator overloading (and function overloading) helps but not enough.    You
> have to be aware of the complex type *everywhere* you go and that's very
> annoying and error prone.  I've been the works with C++, and later with
> Modelica.   I am very happy that Python included *native* complex number
> support.

What kind of awareness do you mean?

There are some operations (as comparison) that work for reals, but not
for complex numbers.  If you want your program to run with complex input,
you have to avoid such operations, whether the data type is native or not.

What other considerations are there?  A typical numeric program should
just run and give complex output when fed complex input.  I made the
experiment with the Perl module Statistics::Descriptive, which was
certainly written without concern for complex input, and it works without
a hitch.  I'm not sure if the (complex) variance of several complex
numbers is a reasonably interpretable quantity, but I'm certain the
maths is done right.  What else do you want?

Anno


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

Date: 11 Jan 2005 06:16:13 -0800
From: arkadyz1@yahoo.com (Arkady Zilberberg)
Subject: CPAN troubles again
Message-Id: <a031bee6.0501110616.784fb08d@posting.google.com>

Hello all,
a few days ago I posted a message describing my problems installing
a module from CPAN (namely, Win32::SerialPort).  Since then, I also
tried to install the required Win32::API manually (even though I
configured CPAN to automatically install dependencies) and failed
yet again - this time 'make' fails with an error during Callback.dll
creation with one unresolved reference: _itoa.
I will try to debug the problem but it still doesn't answer my first
question "Why Win32::SerialPort doesn't create the Makefile?"
Is there anyone familiar with such problems?  I'm using perl 5.8.5
under cygwin/Windows 2000.

Thanks in advance,
    Arkady.


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

Date: Tue, 11 Jan 2005 12:44:21 -0500
From: Digger  <hx_101@hotmail.com>
Subject: Re: Extarcting And Storing a String
Message-Id: <e348u05j28j5hv59neojbprcags7lcuol6@4ax.com>

On Tue, 11 Jan 2005 04:45:10 -0800, Joe Smith <joe@inwap.com> wrote:

>Digger wrote:
>> Is it possible to add another loop inside the while loop to spit out a
>> number "1" to a file only if a link has the FAILURE????
>
>You mean like
>	print LOGFILE "1" if /FAIL/;
>?
>
>That's so obvious.  It's basic Perl programming.
>You have learned the basics, have you not?
>	-Joe


Just starting.. lol

I actually just ordered a book recommended from http://learn.perl.org

Just  a week or two into perl... lol


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

Date: 11 Jan 2005 14:13:17 GMT
From: Martin Kissner <news@chaos-net.de>
Subject: Re: File parsing
Message-Id: <slrncu7nns.7fc.news@maki.homeunix.net>

Arndt Jonasson wrote :
>
> I suggest four changes:
>
> 1) Read from "<>" and remove the $file variable. Then the program can
> get its input specified on the command line, either as files or STDIN.
>
Good practice for me.
I give filenames on the command line, but how can I read fom STDIN ?

Where do I find anything about "<>" in the docs.
perldoc -q "<>", perldoc -q "Diamond-Operator" and others didn't give me
the desired output.

> 2) Remove the $line variable and use the implicit behaviour of $_.
>
Okay, this works well.

> 3) Remove the second period from
>              print "\t$digit1.$digit2. $list[2]\t$list[3]\t$list[4]";
>
Didn't read closely enough :)
> 4) Reset $digit2 to 1 at some appropriate point.
>
Of course - I have overseen this.
> Changes 3 and 4 are needed to make the output conform to what the OP
> wanted.
>
> This line:
>          my ($digit1, $digit2) = 0;
> doesn't set both variables to 0, which maybe you thought it does.
Thanks for the hint; I know how to do it right, now though it's not
needed any more.

Here's my code:

        #!/bin/perl
        
        use warnings;
        use strict;
        
        my ($line, $digit2 ,@list);
        my $top ="";
        my $digit1 = 0;
        
        open (FILE, <>)  or die "Can not open : $!\n";
        while (<FILE>)
        {       
            $digit2++;
            $_ =~s/##//;
            @list = split (/ / ); 
            unless ( $top eq $list[1])
            {       
                $digit1++;
                $digit2=1;
                print "$digit1. $list[1]\n";
            }       
            $top = $list[1];
            print "\t$digit1.$digit2 $list[2]\t$list[3]\t$list[4]";
        }

-- 
Epur Si Muove (Gallileo Gallilei)


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

Date: 11 Jan 2005 15:36:50 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: File parsing
Message-Id: <yzdu0ponibh.fsf@invalid.net>


Martin Kissner <news@chaos-net.de> writes:
> [...]
>
> I give filenames on the command line, but how can I read fom STDIN ?
> 
> Where do I find anything about "<>" in the docs.
> perldoc -q "<>", perldoc -q "Diamond-Operator" and others didn't give me
> the desired output.
>
> [...]
>
> Here's my code:
> 
>         open (FILE, <>)  or die "Can not open : $!\n";
>         while (<FILE>)

But it doesn't work, does it? I meant just read from <>, like this:
        while (<>)

The "diamond" operator <> is described in perlop and perlopentut.
You read from STDIN by using the normal Unix syntax:

        ./myperlscript.pl < file


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

Date: Tue, 11 Jan 2005 08:18:17 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: File parsing
Message-Id: <slrncu7o19.a8p.tadmc@magna.augustmail.com>

jesper <jesper@altern.org> wrote:

> open(FILE,"/yourpath");


You should always, yes *always*, check the return value from ope():

    open(FILE, '/yourpath') or die "could not open '/yourpath'  $!";


> @parse = split($line,'\s');


Have you read the documentation for the split()?

It doesn't look like you have...


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


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

Date: Tue, 11 Jan 2005 09:07:54 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: File parsing
Message-Id: <slrncu7qua.aee.tadmc@magna.augustmail.com>

Martin Kissner <news@chaos-net.de> wrote:
> Arndt Jonasson wrote :

>> 1) Read from "<>" 

> I give filenames on the command line, but how can I read fom STDIN ?


If you want <> to read from STDIN after all of the command line files,
then supply a final argument of '-'.

If you want to read from STDIN independent of what is in @ARGV,
then use <STDIN>.


> Where do I find anything about "<>" in the docs.


The "I/O Operators" section in perlop.pod:

   The null filehandle <> is special ...


> Here's my code:


>         open (FILE, <>)  or die "Can not open : $!\n";


The diamond operator does *input*.

You are reading the 2nd argument from a file (or from STDIN).

Do you mean to be reading the file name from the _contents_ of
some file named on the command line? Does the name of the file
end with a newline?

That is what that code does.


It is unclear to me what you _want_ to do.

Go through all the lines from all the files named on the command line?

   use the diamond operator and _no_ open()
   the diamond operator handles open()ing the files for you

   while ( <> ) {


Go through all the lines from all the files named on the command line
but with an explicit open()?

   foreach my $fname ( @ARGV ) {
      open FILE, $fname or die...
      while ( <FILE> ) {


Go through all the lines from a single file?

     open FILE, 'somefile' or die ...


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


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

Date: 11 Jan 2005 16:24:10 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: File parsing
Message-Id: <yzdpt0cng4l.fsf@invalid.net>


Tad McClellan <tadmc@augustmail.com> writes:
> It is unclear to me what you _want_ to do.

The original poster (who is not Martin) only said this:
        "I have a file in the below format."
so it's not well defined where the input comes from.


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

Date: 11 Jan 2005 15:35:55 GMT
From: Martin Kissner <news@chaos-net.de>
Subject: Re: File parsing
Message-Id: <slrncu7sip.7s4.news@maki.homeunix.net>

Arndt Jonasson wrote :
>
> Martin Kissner <news@chaos-net.de> writes:
>> [...]
>>
>> I give filenames on the command line, but how can I read fom STDIN ?
>> 
>> Where do I find anything about "<>" in the docs.
>> perldoc -q "<>", perldoc -q "Diamond-Operator" and others didn't give me
>> the desired output.
>>
>> [...]
>>
>> Here's my code:
>> 
>>         open (FILE, <>)  or die "Can not open : $!\n";
>>         while (<FILE>)
>
> But it doesn't work, does it? I meant just read from <>, like this:

It does.
But now I see, that I got you wrong.
I started the script withthout "< file" ans then gave the filename on
the command line. I allready was asking myself what would be the sense 
of that.
I have learned something by that anyways.

>         while (<>)
>
I tried this before.
It gave me errors and a strange output.
Calling the script with "< file" of course makes this work, too.

Thank's for the advices.

-- 
Epur Si Muove (Gallileo Gallilei)


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

Date: 11 Jan 2005 15:48:37 GMT
From: Martin Kissner <news@chaos-net.de>
Subject: Re: File parsing
Message-Id: <slrncu7tak.7s4.news@maki.homeunix.net>

Tad McClellan wrote :
>
>
>>         open (FILE, <>)  or die "Can not open : $!\n";
>
>
> The diamond operator does *input*.
>
> You are reading the 2nd argument from a file (or from STDIN).
>
> Do you mean to be reading the file name from the _contents_ of
> some file named on the command line? Does the name of the file
> end with a newline?
>
> That is what that code does.
>
>
> It is unclear to me what you _want_ to do.
>
I used the question from the OP for my own practise.
Things became a little clearer to me by checking out the different
oportunities.

Thank you for your feedback.

-- 
Epur Si Muove (Gallileo Gallilei)


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

Date: Tue, 11 Jan 2005 10:33:02 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: File parsing
Message-Id: <110120051033029465%jgibson@mail.arc.nasa.gov>

In article <slrncu7nns.7fc.news@maki.homeunix.net>, Martin Kissner
<news@chaos-net.de> wrote:


> Here's my code:
> 
>         #!/bin/perl
>         
>         use warnings;
>         use strict;
>         
>         my ($line, $digit2 ,@list);

These are not needed.

>         my $top ="";
>         my $digit1 = 0;
>         
>         open (FILE, <>)  or die "Can not open : $!\n";
>         while (<FILE>)

For usenet posting purposes, it is best to use the special DATA file
handle and place input file lines after the __DATA__ terminator at the
end of the program.

>         {       
>             $digit2++;
>             $_ =~s/##//;

There is no need to delete the ## characters if you are just going to
split the line.

>             @list = split (/ / ); 

If you use the default /\s+/ pattern you will get rid of the new line.

>             unless ( $top eq $list[1])
>             {       
>                 $digit1++;
>                 $digit2=1;
>                 print "$digit1. $list[1]\n";
>             }       
>             $top = $list[1];

No need to assign $list[1] to $top if they are equal, so move this
inside the unless block.

>             print "\t$digit1.$digit2 $list[2]\t$list[3]\t$list[4]";

You can use join and list slice here.

>         }

Resulting in the following submission for your scrutiny:

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

my $top = '';
my( $digit1, $digit2);

while (<DATA>)
{       
  $digit2++;
  my @list = split;
  unless ( $top eq $list[1])
  {       
    $digit1++;
    $digit2 = 1;
    $top = $list[1];
    print "$digit1. $top\n";
  }       
  print "\t$digit1.$digit2 ", join("\t", @list[2..4]), 
    "\n";
}
__DATA__
## COMP1: MAIN: SUB1: OK
## COMP1: MAIN: SUB2: N/A
## COMP2: MAIN: SUB1: OK



__OUTPUT__
1. COMP1:
        1.1 MAIN:       SUB1:   OK
        1.2 MAIN:       SUB2:   N/A
2. COMP2:
        2.1 MAIN:       SUB1:   OK


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


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

Date: 11 Jan 2005 16:17:11 GMT
From: xhoster@gmail.com
Subject: Re: GLOB vs IO::Handle
Message-Id: <20050111111711.451$9N@newsreader.com>

bill <please_post@nomail.edu> wrote:
> I want to write a sub that takes either a string which is interpreted
> as a filename to be opened and read, or an open read handle.  The
> question is how to test for the latter?

You don't.  You gave the user two options, a plain old scalar, whose string
value is used as a filename, or a handle.  Therefore, if it isn't a plain
old scalar, it must be a handle.  Use it like a handle.  If they send in
something that is neither one of these things, they should get bitched at.
But just let perl do the bitching, at the point where the whatever-it-is is
used as a handle.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 11 Jan 2005 16:35:11 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: GLOB vs IO::Handle
Message-Id: <cs0v7v$51f$1@mamenchi.zrz.TU-Berlin.DE>

bill  <please_post@nomail.edu> wrote in comp.lang.perl.misc:
> 
> 
> 
> I want to write a sub that takes either a string which is interpreted
> as a filename to be opened and read, or an open read handle.  The

[...]

> By this point I get the distinct feeling that I just don't know
> enough about this wheel to mess around with reinventing it.  What's
> the tried-and-true idiom for doing what I want to do?

    if ( defined fileno $x ) {
        # it's an open file handle
    }

Anno


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

Date: Tue, 11 Jan 2005 18:04:45 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: GLOB vs IO::Handle
Message-Id: <cs1456$6md$1@sun3.bham.ac.uk>



xhoster@gmail.com wrote:

> bill <please_post@nomail.edu> wrote:
> 
>>I want to write a sub that takes either a string which is interpreted
>>as a filename to be opened and read, or an open read handle.  The
>>question is how to test for the latter?
> 
> 
> You don't.  You gave the user two options, a plain old scalar, whose string
> value is used as a filename, or a handle.  Therefore, if it isn't a plain
> old scalar, it must be a handle.  Use it like a handle.  If they send in
> something that is neither one of these things, they should get bitched at.
> But just let perl do the bitching, at the point where the whatever-it-is is
> used as a handle.

It is worth pointing out that a scalar varialble can be one of there 
things: a plain old scalar, a reference or a (fake) GLOB.

Now the use of fake GLOBs rather than GLOBrefs is frowned upon by me but 
if you want to leave the option open you need check that a scalar 
variable is a plain old scalar thus:

   ref(\$thing) eq 'SCALAR'

or if you are feeling really pendantic...

   !ref($thing) && ref(\$thing) ne 'GLOB'

Of course this does not cope with objects that are can be treated as 
strings because they overload "".

Even if you could cope with that what would you do with object that can 
be treates as both strings and filehandles?



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

Date: 11 Jan 2005 17:06:40 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to change configuration on installed Perl ?
Message-Id: <cs1130$6kj$1@mamenchi.zrz.TU-Berlin.DE>

Yan <a@b.c> wrote in comp.lang.perl.misc:
> Hi !
> 
> I wonder if there is a command for changing config info (stored in Config.pm
> and others...) on an installed version of Perl (5.8.6) whithout reinstalling
> it fully.
> My Perl is working fine for most tasks, but if I want to install a new
> module or use scripts like pod2html, it won't work because of wrong paths in
> config files (my perl was built in /users/user1 and I want to copy it in
> /users/user2 on another machine).
> I have tried to replace /users/user1 with /users/user2 in Config.pm and it
> seems to work, but I would prefer a built-in "reconfig" command, if there is
> any...

There isn't, and the only way to do this right is to recompile.  Parts of
the configuration is compiled into the perl binary, so there's no guarantee
that changing something in Config.pm makes perl use the new value.

Of course, you can install modules and executables anywhere, not only the
default location, so if you remember to do that, or teach it to CPAN.pm,
you don't have to recompile.

For a hack, you may be able to install one or more symlinks in the place(s)
perl expects and point them to where you want them to go.

Anno


Anno


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

Date: Tue, 11 Jan 2005 17:47:58 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: How to convert a string "-" to an operator -?
Message-Id: <cs135o$69e$1@sun3.bham.ac.uk>



Peter Wyzl wrote:

> "Diandian Zhang" <zhangdidi@hotmail.com> wrote in message 
> news:7d12548d.0501110440.434548a6@posting.google.com...
> : Hi, everyone,
> :
> : I think the question is strange. But I really want get the value of
> : mathematical formal given in form of a string. For example from the
> : string "256 - 64", I want get the value (256 - 64). What I did was:
> 
> You could 'eval' the string:
> 
> $value = eval $str;
> 
> Read up on string eval.

Don't just read "perldoc -f eval".

Be aware also that the person providing the string to your program will 
be able to execute arbitray code (Perl code and external programs) as 
the user-id under which the Perl script is running.

Think hard if this is acceptable to you now and likely to be accecptable 
also in all contexts where your script may get run in future.



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

Date: Tue, 11 Jan 2005 10:40:35 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: How to convert a string "-" to an operator -?
Message-Id: <110120051040356658%jgibson@mail.arc.nasa.gov>

In article <7d12548d.0501110440.434548a6@posting.google.com>, Diandian
Zhang <zhangdidi@hotmail.com> wrote:

> Hi, everyone,
> 
> I think the question is strange. But I really want get the value of
> mathematical formal given in form of a string. For example from the
> string "256 - 64", I want get the value (256 - 64). What I did was:

[simple math calculator snipped]

> Are there any better ways to solve the problem? Thanks!

Did you look on CPAN? Check out Math::Symbolic (I haven't used it).


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


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

Date: Tue, 11 Jan 2005 17:19:38 +0000
From: Richard Gration <richard@zync.co.uk>
Subject: Lexical filehandles must be simple scalars (not eg hash elements) ?
Message-Id: <pan.2005.01.11.17.19.38.196331@zync.co.uk>

Hi All,

I've happened on this situation and I'm wondering if I'm correct. The code
below illustrates my point, in the sub log_write. The commented out print
line (#1) generates a "String found where operator expected" error, but I
don't see why it has to. I don't see why print #1 shouldn't parse and
indeed execute, it seems to be a deficiency in the parser. Can anybody
please explain?

Cheers
Rick

------------------------------------
#!/usr/bin/perl

use strict;
use warnings;

my $c = config();
log_write($c,'Start run');
log_write($c,'End run');

sub config {
	my $config = {};
	open my $fh,'>','log.log' or die "Pants: $!\n";
	$config->{log_fh} = $fh;
	$config->{log_to_file} = 1;
	return $config;
}

sub log_write {
	my ($config,@log) = @_;
	return unless $config->{log_to_file};

	# print #1
	# This is what I would like to be able to do
	#	but it generates an error
	# print $config->{log_fh} "$_\n" for @log;

	# print #2
	# This is what I must do
	my $fh = $config->{log_fh};
	print $fh "$_\n" for @log;
}


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

Date: 11 Jan 2005 17:33:21 GMT
From: xhoster@gmail.com
Subject: Re: Lexical filehandles must be simple scalars (not eg hash elements) ?
Message-Id: <20050111123321.560$9K@newsreader.com>

Richard Gration <richard@zync.co.uk> wrote:
> Hi All,
>
> I've happened on this situation and I'm wondering if I'm correct.

Don't wonder.  Just read the documentation for "print".

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 11 Jan 2005 17:41:18 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Lexical filehandles must be simple scalars (not eg hash elements) ?
Message-Id: <cs133u$8d6$1@mamenchi.zrz.TU-Berlin.DE>

Richard Gration  <richard@zync.co.uk> wrote in comp.lang.perl.misc:
> Hi All,
> 
> I've happened on this situation and I'm wondering if I'm correct. The code
> below illustrates my point, in the sub log_write. The commented out print
> line (#1) generates a "String found where operator expected" error, but I
> don't see why it has to. I don't see why print #1 shouldn't parse and
> indeed execute, it seems to be a deficiency in the parser. Can anybody
> please explain?
> 
> Cheers
> Rick
> 
> ------------------------------------
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 
> my $c = config();
> log_write($c,'Start run');
> log_write($c,'End run');
> 
> sub config {
> 	my $config = {};
> 	open my $fh,'>','log.log' or die "Pants: $!\n";
> 	$config->{log_fh} = $fh;
> 	$config->{log_to_file} = 1;
> 	return $config;
> }
> 
> sub log_write {
> 	my ($config,@log) = @_;
> 	return unless $config->{log_to_file};
> 
> 	# print #1
> 	# This is what I would like to be able to do
> 	#	but it generates an error
> 	# print $config->{log_fh} "$_\n" for @log;

If the file handle isn't a simple variable, the simplest thing is to put
block braces around it (untested):

        print { $config->{log_fh} } "$_\n" for @log;

> 	# print #2
> 	# This is what I must do
> 	my $fh = $config->{log_fh};
> 	print $fh "$_\n" for @log;
> }

That's another possibility.  The last paragraph of "perldoc -f print"
points this out.

The parser has a hard time with things in the "indirect object slot".
It must parse what could be the concatenation of two expressions.
Without a comma (or other keyword) to indicate the end of the first
one, only very simple expressions can be parsed.

Anno


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

Date: Tue, 11 Jan 2005 18:38:21 GMT
From: "Todd W" <toddrw69@excite.com>
Subject: Re: Lexical filehandles must be simple scalars (not eg hash elements) ?
Message-Id: <x2VEd.13452$_X7.1043@newssvr33.news.prodigy.com>


"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:cs133u$8d6$1@mamenchi.zrz.TU-Berlin.DE...
> Richard Gration  <richard@zync.co.uk> wrote in comp.lang.perl.misc:
> > Hi All,
> >
<snip />
> >
> > sub log_write {
> > my ($config,@log) = @_;
> > return unless $config->{log_to_file};
> >
> > # print #1
> > # This is what I would like to be able to do
> > # but it generates an error
> > # print $config->{log_fh} "$_\n" for @log;
>
> If the file handle isn't a simple variable, the simplest thing is to put
> block braces around it (untested):
>
>         print { $config->{log_fh} } "$_\n" for @log;
>
> > # print #2
> > # This is what I must do
> > my $fh = $config->{log_fh};
> > print $fh "$_\n" for @log;
> > }
>
> That's another possibility.  The last paragraph of "perldoc -f print"
> points this out.
>
> The parser has a hard time with things in the "indirect object slot".
> It must parse what could be the concatenation of two expressions.
> Without a comma (or other keyword) to indicate the end of the first
> one, only very simple expressions can be parsed.
>

Thats why I like to use standard method notation:

becaue $fh is an IO::File object, you can just say:

$fh->print( ... );

from the example, I'd use:

> > $config->{log_fh}->print( map "$_\n", @log );

looks alot "OO"yer to me ;0)

Todd W.




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

Date: 11 Jan 2005 06:35:22 -0800
From: "DKW" <uffesterner@spamhole.com>
Subject: Re: portable no warnings "uninitialized"
Message-Id: <1105454122.409585.111030@f14g2000cwb.googlegroups.com>


Gunnar Hjalmarsson wrote:
> The options I can see are to either fix the code so it doesn't
generate
> uninitialized warnings, or turn off warnings in the production code
(but
> keep it enabled during development and maintenance).

As I wrote in the first post, I want to turn of _only_ the warning
category "uninitialized",
which seems to be possible with the code:
no warnings "uninitialized";
at least from v5.6.1.

However, this will give an error if you try it in perl versions prior
to 5.6 when the warnings module was introduced.

If I rephrase my question:
Can you at runtime check for existence for a module,
and use (or no) it if it exists?



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

Date: Tue, 11 Jan 2005 16:23:25 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: portable no warnings "uninitialized"
Message-Id: <34i9ijF4butljU1@individual.net>

DKW wrote:
> Gunnar Hjalmarsson wrote:
>> The options I can see are to either fix the code so it doesn't 
>> generate uninitialized warnings, or turn off warnings in the
>> production code (but keep it enabled during development and
>> maintenance).
> 
> As I wrote in the first post, I want to turn of _only_ the warning 
> category "uninitialized",

I understood that, but I wasn't able to figure out a way to do it if you
want the script to also work with pre 5.6.0 Perl versions.

> If I rephrase my question:
> Can you at runtime check for existence for a module, and use (or no)
> it if it exists?

For an ordinary module you can do e.g.:

     BEGIN { eval "use SomeModule" }

but the problem with "warnings" is that it's a pragma whose effect is
set lexically.

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


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

Date: Tue, 11 Jan 2005 15:46:11 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: portable no warnings "uninitialized"
Message-Id: <7xSEd.51417$6l.37156@pd7tw2no>

In article <1105450844.477412.114770@f14g2000cwb.googlegroups.com>,
 "DKW" <uffesterner@spamhole.com> writes:
[In response to my suggestion to insert "local $^W = 0"]
>Wouldn't that turn of _all_ warnings locally, not just the
>"uninitialized" category?

Yes.  Selective warnings didn't exist in the perls you're trying
to make this work on.

What you could do instead is set up a handler for $SIG{__WARN__}
and inspect the text before deciding what to do with it.  See
perldoc perlvar.  

-- 
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/


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

Date: Tue, 11 Jan 2005 18:16:16 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: portable no warnings "uninitialized"
Message-Id: <cs14ro$741$1@sun3.bham.ac.uk>



Gunnar Hjalmarsson wrote:

> DKW wrote:
> 
>> Gunnar Hjalmarsson wrote:
>>
>>> The options I can see are to either fix the code so it doesn't 
>>> generate uninitialized warnings, or turn off warnings in the
>>> production code (but keep it enabled during development and
>>> maintenance).
>>
>>
>> As I wrote in the first post, I want to turn of _only_ the warning 
>> category "uninitialized",
> 
> 
> I understood that, but I wasn't able to figure out a way to do it if you
> want the script to also work with pre 5.6.0 Perl versions.
> 
>> If I rephrase my question:
>> Can you at runtime check for existence for a module, and use (or no)
>> it if it exists?
> 
> 
> For an ordinary module you can do e.g.:
> 
>     BEGIN { eval "use SomeModule" }
> 
> but the problem with "warnings" is that it's a pragma whose effect is
> set lexically.

That does not prevent the more verbose form from working:

BEGIN {
   if ( eval { require warnings; 1 } ) {
      warnings->unimport('uninitialized');
   }
}

Or even just

BEGIN {
   eval {
     require warnings;
     warnings->unimport('uninitialized');
   }
}




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

Date: Tue, 11 Jan 2005 08:41:49 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: system fails
Message-Id: <slrncu7pdd.a8p.tadmc@magna.augustmail.com>

Petterson Mikael <mikael.petterson@ericsson.se> wrote:

> my @args = ("${arc_bin}/addproj", "-p $project", "-r $release", "-i 
> $isit");
> system(@args) == 0 or die "could not execute $!";


You have more than one argument per list element.

   my @args = ("${arc_bin}/addproj", '-p', $project, '-r', $release, 
                                     '-i', $isit);


> sub validateproject {
>    local $p=$_[0]; # project
>    local $r=$_[1]; # release
>    local $ir=$_[2];# isit


Why are you using package variables rather than lexical variables?


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


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

Date: 11 Jan 2005 17:21:41 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: system fails
Message-Id: <cs11v5$6kj$2@mamenchi.zrz.TU-Berlin.DE>

Tad McClellan  <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
> Petterson Mikael <mikael.petterson@ericsson.se> wrote:

> > sub validateproject {
> >    local $p=$_[0]; # project
> >    local $r=$_[1]; # release
> >    local $ir=$_[2];# isit
> 
> 
> Why are you using package variables rather than lexical variables?

That's part of the given system, outside OP's control.  From what I've
seen, it's a Perl 4 program.  There isn't enough of it to say if it's good
Perl 4 code.  The use of "$true" and "$false" for booleans is not a good
sign.

Anno


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

Date: Tue, 11 Jan 2005 09:55:35 -0800
From: "Alfred Z. Newmane" <a.newmane.remove@eastcoastcz.com>
Subject: Re: system fails
Message-Id: <34ii8rF4cc634U1@individual.net>

Arndt Jonasson wrote:
> Petterson Mikael <mikael.petterson@ericsson.se> writes:
>>
>> I am executing the following perl script:
>>
>> my @args = ("${arc_bin}/addproj", "-p $project", "-r $release", "-i
>> $isit");
>> system(@args) == 0 or die "could not execute $!";
>>
>> The scalars are set to:
>>
>> $project = 'espresso';
>> $release = 'rbssw/1.3';
>> $isit = '3.0';
>>
>> In the perl script 'addproj' there is a validate method that takes 3
>> args. ( I don't have access to edit the script).
>>
>> I get the following error message.
>>
>> /app/arc/latest/bin/addproj: project/subproject/isit does not exist
>> system /app/arc/latest/bin/addproj -p espresso -r rbssw/1.3 -i 3.0
>> failed: 256 at /home/eraonel/dtest/dtest_perl-0.1/run_dtest.pl line
>> 162.
>
> Maybe something interesting can be seen on line 162 in that script,
> but my first suspicion is that the argument list @args does not
> contain what you want. Look at the first paragraph in the description
> of 'system'. With your code, "-p espresso" will become _one_ argument,
> not two.
>
> Try
>   my @args = ("${arc_bin}/addproj -p $project -r $release -i $isit");
> instead.

Actually it should bt my $args (or $cmd, by convention), that is, a 
scalar, not an array. 




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

Date: Tue, 11 Jan 2005 13:04:02 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: system fails
Message-Id: <U4SdnYOg_IaPiHncRVn-rQ@comcast.com>

Anno Siegel wrote:

> Tad McClellan  <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
>> Petterson Mikael <mikael.petterson@ericsson.se> wrote:
> 
>> > sub validateproject {
>> >    local $p=$_[0]; # project
>> >    local $r=$_[1]; # release
>> >    local $ir=$_[2];# isit
>> 
>> 
>> Why are you using package variables rather than lexical variables?
> 
> That's part of the given system, outside OP's control.  From what I've
> seen, it's a Perl 4 program.  There isn't enough of it to say if it's good
> Perl 4 code.  The use of "$true" and "$false" for booleans is not a good
> sign.
> 
Frankly, the fact that it's Perl 4 code is not a good sign.  All too 
often, it's Perl 4 not because the author was actually coding for
Perl 4, but because he was copying Perl 4 code he didn't understand.
-- 
             Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"


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

Date: Tue, 11 Jan 2005 15:56:09 +0000 (UTC)
From: Steve Lidie <lusol@Dragonfly.cc.lehigh.edu>
Subject: Re: Tk: Call subroutine when MainWindow is realized?
Message-Id: <cs0sup$5554$1@ws2.cc.lehigh.edu>

Josef Moellers <josef.moellers@fujitsu-siemens.com> wrote:

You'll get better, more, help in comp.lang.perl.tk.

> Steve Lidie wrote:
>> zentara <zentara@highstream.net> wrote:
>> 
>>>On Mon, 10 Jan 2005 09:17:24 +0100, Josef Moellers
>>><josef.moellers@fujitsu-siemens.com> wrote:
>>>
>>>
>>>>Hi,
>>>>
>>>>In a small(ish) application that communicates with a smart card reader, 
>>>>I'd like to test the link at the beginning. Since the MainLoop is not 
>>>>yet called, I seem to be unable to create a Dialog to tell the user.

I'm having trouble understanding what you really want to do from above.

>>>>
>>>>Is there any way to call a sub the first thing after the MainWindow is 
>>>>created?
>>>
>>>In perldoc Tk::Widget there is
>>>$mw->waitVisibility;
>>>and 
>>>$mw->waitVariable(\$var);
>>>and
>>>$mw->waitWindow;
>>>
>> 
>> 
>> Use waitVisibility().
> 
> I don't see how this solves my problem. I'd need two threads: one which 
> realizes the MainWindow, one which waits for its visibility.

?

Anyway, Tk is n ot thread-safe.

> 
> I had hoped for a callback mechanism, e.g.
> 
> waitVisibility($top, \&checkconnection);
> 

Again, what do you really want to do? And comp.lang.perl.tk is a better place to ask ;)


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

Date: Tue, 11 Jan 2005 08:46:48 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: URGENT --- Aspell Scores
Message-Id: <slrncu7pmo.a8p.tadmc@magna.augustmail.com>

Sum <sumitra@gmail.com> wrote:

> Subject: URGENT --- Aspell Scores
           ^^^^^^
           ^^^^^^

Including that in your Subject *decreases* your chances of getting
an answer.

I suggest you leave it out next time.


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


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

Date: Tue, 11 Jan 2005 08:44:54 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Writing to Filehandle
Message-Id: <slrncu7pj6.a8p.tadmc@magna.augustmail.com>

Diana <dianaHaden@hotmail.com> wrote:

> I want to get the row and col in number where the filehandle has written,


There are no rows and columns in a file, just a stream of bytes.


> is it possible to get the values? , 


You can get the byte position of the file pointer with:

   perldoc -f tell


> another how can I force fully move the 
> position of curser so that it writes on/from row,col I want


You can set the position of the file pointer with:

   perldoc -f seek


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


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

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


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