[22277] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4498 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 1 03:05:40 2003

Date: Sat, 1 Feb 2003 00:05: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           Sat, 1 Feb 2003     Volume: 10 Number: 4498

Today's topics:
        "Syntax Error at Line: (ZZ)
    Re: "Syntax Error at Line: <noreply@gunnar.cc>
    Re: A Good Perl Developing Enviroment  <jbtest@athotmail.com>
    Re: Attitude to Perl in academia (Andrew Allaire)
    Re: Attitude to Perl in academia <goldbb2@earthlink.net>
    Re: Crossposting (was: Fetchrow Question) <smiley@uvgotemail.com>
    Re: Getting Values Out of An Object:  How Do I Do This? (Myron Turner)
    Re: Multi-line (with \n's) regex search <krahnj@acm.org>
    Re: my sorting is slow <abigail@abigail.nl>
    Re: Net:Ftp output from site command? (Charles DeRykus)
    Re: newbie EASY problem :-) <n_joeller@sharblbaziilyar.com>
    Re: newbie EASY problem :-) <mgjv@tradingpost.com.au>
    Re: RFC Date <krahnj@acm.org>
    Re: Scope in a format? <skuo@mtwhitney.nsc.com>
    Re: Scope in a format? <jackstraw@witchita>
    Re: Scope in a format? <jackstraw@witchita>
    Re: Using split with "df -k" <abigail@abigail.nl>
        wantnumber? How to tell numeric from string context <ekulis@apple.com>
    Re: wantnumber? How to tell numeric from string context <uri@stemsystems.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 31 Jan 2003 21:24:49 -0800
From: z@thrivenet.com (ZZ)
Subject: "Syntax Error at Line:
Message-Id: <z-ya02408000R3101032124490001@news.spiritone.com>


Can any one figure out where I've gone wrong?? Here's the Screen I get when
I submit my form.  Below I'll paste the code that relates to it. 

I'm a very novice. This was essentiall a cut and paste form which I'm
trying to customize. Got all but this part working--well it did work once,
with incorrect data.... anyway... what I'm trying to say is please don't
get too technical! I did check out two books from the library, so while
this query is "out there" I'll continue to try to figure this thing out!!

Thanks so much all!

--zz


The error message:


Unable to process ppporder form

Syntax error in form/ppporder.cfg at line 279:$reply="Thank you for your
order. \n\nWe will ship it as soon as possible. We will add our shipping
charge to your order. You will receive an email with the total once we have
shipped your order.\n\n$name\n$organization\n$address\n\nOrder\n

\nQty Item                Price  Ext
Price\n=============================================================\n$order
\n\n                                          Subtotal:  $subtotal\n                                              
Tax:  $tax\n                                          Shipping: 
$shipping\n                                             Total:  $total\n
\n\n

$comments
\n\n\n
\nYour order will be shipped to (unless otherwise noted):
\n
\n$organization
\nAttn: $name
\n$address
\n
\n\nThank your for choosing Practical Psychology Press!
\n
\n\n\n\n"; ;




-- Here's the original code (plus some....I didn't include the whole file,
other parts SEEM to work fine...):





if ("")
$tax=$subtotal*(/100);
else
$tax=0;
endif

$shipping="";
$total=$subtotal+$tax+$shipping;

$subtotal=sprintf("%8.2f",$subtotal);
$total=sprintf("%8.2f",$total);
$tax=sprintf("%8.2f",$tax);
$shipping=sprintf("%8.2f",$shipping);

$address="$street<br>$street1<br>$city, $state, $zip<br>";

$reply="Thank you for your order. \n\nWe will ship it as soon as possible.
We will add our shipping charge to your order. You will receive an email
with the total once we have shipped your
order.\n\n$name\n$organization\n$address\n\nOrder\n<pre>\nQty  Item               
Price  Ext
Price\n=============================================================\n$order
\n\n                                          Subtotal:  $subtotal\n                                              
Tax:  $tax\n                                          Shipping: 
$shipping\n                                             Total: 
$total\n</pre>\n\n<p>$comments</p>\n\n\n<br>\nYour order will be shipped to
(unless otherwise noted):<br>\n<br>\n$organization<br>\nAttn:
$name<br>\n$address<br>\n<br>\n\nThank your for choosing <a
href="http://www.practicalpsychologypress.com/">Practical Psychology
Press</a>!<br>\n<br>\n\n\n\n";

format screen
<HEAD>
</HEAD>
<body bgcolor="#ffffcc" link="#000066" alink="#ff3366" vlink="#333333">
$navbar_top

$reply
</body>
 .


$address =~ s/<br>/\n/g;
$reply="<blockquote><h3>Thank you for your order, we will ship it as soon
as possible. <br/>We will add our shipping charge to your order. You will
receive another order confirmation email with the total once we have
processed and shipped your
order.</h3>\n\n$name<br>\n$organization<br>\n$address<br>\n\nOrder<br>\n<pre>
\nQty Item                Price  Ext
Price\n=============================================================\n$order
\n\n                                          Subtotal:  $subtotal\n                                              
Tax:  $tax\n                                          Shipping: 
$shipping\n                                             Total: 
$total\n</pre>\n\n<p>$comments</p>\n\n\n<br>\nYour order will be shipped to
(unless otherwise noted):<br>\n<br>\n$organization<br>\nAttn:
$name<br>\n$address<br>\n<br>\n\nThank your for choosing <a
href="http://www.practicalpsychologypress.com/">Practical Psychology
Press</a>!<br>\n<br>\n\n</blockquote>\n\n";
$reply =~ s/<.+>//g;

format email to $email_addr subject "Your $organization order."

$reply

 .


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

Date: Sat, 01 Feb 2003 06:14:14 GMT
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: "Syntax Error at Line:
Message-Id: <WAJ_9.9025$LY2.533792@newsc.telia.net>

ZZ wrote:
> Can any one figure out where I've gone wrong??
> ...
> href="http://www.practicalpsychologypress.com/">Practical Psychology
-------^----------------------------------------^

Doublequotes within doublequotes must be escaped:

href=\"http://www.practicalpsychologypress.com/\">Practical Psychology

/ Gunnar

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



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

Date: Fri, 31 Jan 2003 23:20:15 -0800
From: James Bondo <jbtest@athotmail.com>
Subject: Re: A Good Perl Developing Enviroment 
Message-Id: <MPG.18a51507e8ea2845989682@news.easystreet.com>

In article <iz4W9.43403$aG4.2586200
@twister.austin.rr.com>, alvarof2@hotmail.com says...
> 
> 
> Fellow Perl Netters:
> 
> I have a newbie question:
> 
> What would be a good Perl Developing Enviroment for
> managing and developing Perl projects?
> (Visual Developer Studio-like)
> 
> Any suggestions will be appreciated.
> 
> Thanks in advance,
> 
> A. Fuentes
> 512-297-9937
> 

I've been using vim or gvim (http://www.vim.org)
with the exuberant ctags script that allows me to 
display and jump to subroutines.

-- bondo


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

Date: 31 Jan 2003 15:21:38 -0800
From: Andrew.Allaire@na.teleatlas.com (Andrew Allaire)
Subject: Re: Attitude to Perl in academia
Message-Id: <6bdb91de.0301311521.43f51ac1@posting.google.com>

rat_tank@yahoo.com (Rat Tank) wrote in message news:<ae14ba57.0301300939.2d47cb01@posting.google.com>...

Perl makes stuff way too easy for you to deserve full credit. Do you
want credit for breathing too? But I think you should get some
imagination credit for trying to validate the acedemics' distain for
Perl--just try it on a less informed audience next time.


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

Date: Fri, 31 Jan 2003 23:50:26 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Attitude to Perl in academia
Message-Id: <3E3B5212.1BCF0163@earthlink.net>

Rat Tank wrote:
> Uri Guttman wrote:
> > >>>>> "RT" == Rat Tank <rat_tank@yahoo.com> writes:
> >
> > huh? perl has no typing system as do most other languages. so how
> > can you dreive one?
>
>     Actually, I think you'll find that Perl does have a typing system,
> but it's of the form of languages like ML or Smalltalk; it's an
> implicit typing system.

No -- with ML and Smalltalk, every variable's type is inferred *at the
time that the function is typed in*... in other words, at compile time.

At runtime, you must pass a variable of the appropriate type to the
function.

In perl, there is no such compile-time typing.  A scalar variable
(something like $scalar), or a scalar element of an array or hash (that
is, $array[$n], or $hash{$key}) has *no* compile-time type attached to
it.

Scalar variables can be simple-scalars (undef(), or a number or a
string), or they can be references to other structurs (a ref to a
scalar, or a ref to a hash, or a ref to an array, or a ref to a
subroutine).

(I'm ignoring dual-type vars like $!, and typeglobs, for the sake of
simplicity)

> The programmer may well not know the exact type,

   perldoc -f ref

> but the underlying compiler does have a concept of the type of
> each symbol, and infers it automatically at runtime from context.

I don't think that "infer" is the right term -- instead, say that the
interpreter will *coerce* a variable to the appropriate type.

If you use a string as a number, it numifys the string.  If you use a
number as a string, it stringifies the number.  If you use a reference
of some sort as a string, it gets stringified.  If you use a string as a
reference, it will (if 'use strict' isn't enabled) fetch the appropriate
variable from the symbol table, and thus use the string as a reference.

> Because the type is hidden, that makes it even more severe that the
> Perl typer has PROVABLE BUGS.

Show us one of these "provable bugs" and perhaps we'll believe you.

> Such un-typesafeness can result in garbage casts,

Like what?

> and worse yet, regular buffer overflows.

Show us a perl program where "un-typesafeness" causes a buffer overflow.

[snip nonsense about Turing Completeness, where OP demonstrates his
complete and utter ignorance]

> >   RT>     Perl's reference counting system of garbage collection can
> >   RT> sometimes result in memory leaks, as opposed to the more
> >   RT> thorough graph traversal employed in other languages.
> >
> > that is a known thing and can be handled if you know how to deal
> > with circular refs. and if you emply them, you should know how to
> > destroy them.
>
>     The point of garbage collection is that one shouldn't have to
> destroy things manually.

The point of garbage collection is to free the programmer from *most* of
the nuisances of freeing things manually.  There is no magically gc
which can automatically free *everything* which is unused.

For example, consider this Java program:
   public class Foo {
      public static void main(String[] argv) {
         int unused[] = new int[100000];
         do_other_stuff_without_that_unused_thingy();
      }
   }

If you had a magic gc, it would free up those hundred-thousand ints
immediately, knowing that they wouldn't be used.  Instead, they aren't
going to ever get freed until the program exits.  To force them to get
freed in a timely manner, you would have to do 'unused = null;' before
do_other_stuff_...().

> This isn't a rare occurence either; Perl regularly uses circular refs
> in such common structures as hashes and arrays,

No, it doesn't.

Show me even one standard module where circular refs are used.

> and memory leaks are therefore quite frequent.

Pfff.

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


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

Date: Sat, 1 Feb 2003 02:15:45 -0500
From: "Smiley" <smiley@uvgotemail.com>
Subject: Re: Crossposting (was: Fetchrow Question)
Message-Id: <v3mt6q29lb7eec@corp.supernews.com>

> Think!
>
> The whole point crossposted article is that is a single article that
> appears in multiple groups because is has multiple items in the
> Newsgroup line.
>
> If the article must either appear in all groups listed or none.

I've never had any inclinations to figure our how newsgroups worked before,
I thought crossposting worked in a simmilar way to email CC's - apparently I
was wrong.

> What was the "problem"?  Was it that you were too impatient to wait
> for the moderator?

What moderator??  If I don't know what group the problem resides in, how
could I possibly know to contact the right moderator?

> My post to alt.perl at all?  Surely there's nobody cluefull who'd
> answer in alt.perl who wouldn't answer in the mainstream Perl groups?

I don't understand, do you find something wrong with alt.perl?  Why is it
not a mainstream Perl group and what do you consider to be the mainstream
Perl groups?  Is there some taboo against posting in alt.perl that I don't
know about?




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

Date: Sat, 01 Feb 2003 03:43:05 GMT
From: mturner@ms.umanitoba.ca (Myron Turner)
Subject: Re: Getting Values Out of An Object:  How Do I Do This?  Thanks!
Message-Id: <3e3b404b.532833153@news.wp.shawcable.net>

On 22 Jan 2003 16:39:04 -0800, opensourcedrm@netscape.net
(opensourcedrm) wrote:

>Suppose I have this:
>
>$data = [
>          {
>            first => 'Jonathan',
>            last => 'Eisenzopf',
>            email => 'eisen@pobox.com'
>          },
>          {
>            first => 'Larry',
>            last => 'Wall',
>            email => 'larry@wall.org'
>	  }
>	 ];
>
>How do I get the value Jonathan?
>
Either:
    $data->[0]->{first}
or 
     $data->[0]{first}
or
  @$data[0]->{first}


$data is a reference to an anonymous array; hence
   $data->[0]
and $data->[0] is in turn a reference to an anonymouse hash, hence:
   $data->[0]->{first} or   $data->[0]{first} 
The second arrow is optional.

check out the  perlref man page or perldoc page.




Myron Turner
www.room535.org


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

Date: Sat, 01 Feb 2003 03:14:13 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Multi-line (with \n's) regex search
Message-Id: <3E3B3B7C.5B4AD360@acm.org>

Chris wrote:
> 
> I'm attempting to scan a C header file (.h) looking for typedef struct
> declarations.  When found, I want to read each element of the struct
> saving the type and element name into a hash respectively.

This might be what you are looking for:

http://search.cpan.org/author/MHX/Convert-Binary-C-0.05/


John
-- 
use Perl;
program
fulfillment


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

Date: 31 Jan 2003 23:09:22 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: my sorting is slow
Message-Id: <slrnb3m0h2.ngt.abigail@alexandra.abigail.nl>

someuser (user@someserver123abc.com) wrote on MMMCDXL September MCMXCIII
in <URL:news:3E3AE114.45FA2DC1@someserver123abc.com>:
//  why is this sorting so damn slow?
//  I'm tring to sort out a table by column.
//  yeah, I know, lots of for loops.
//  what's better?

It's hard to come with something that's worse. It looks like you just
want to sort an array by a certain field. This is answered in the FAQ.


Abigail
-- 
perl -wlpe '}{$_=$.}{' file  # Count the number of lines.


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

Date: Sat, 1 Feb 2003 01:06:44 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Net:Ftp output from site command?
Message-Id: <H9Lv38.KvF@news.boeing.com>

In article <3e2aeced@mtunews.mtu.edu>,
Shawn Laemmrich <swlaemmr@mtu.edu> wrote:
>
>Trying to do something which I thought would be relatively simple.....
>
>I want to connect to a ftp site, run several site commands and capture
>the output for later processing.... something like this:
>
>$ftp->login("blah","oog");
>$x = $ftp->site("info blah");

Assuming the site command is supported, text output from the
last command executed can be captured (perldoc Net::Cmd): 

( $ftp->site(...) or die $ftp->message ) and
    $x = $ftp->message;

[untested]
 
--
Charles DeRykus


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

Date: Sat, 01 Feb 2003 00:10:21 GMT
From: Noerd <n_joeller@sharblbaziilyar.com>
Subject: Re: newbie EASY problem :-)
Message-Id: <3E3B105B.2BB8F0A0@sharblbaziilyar.com>

> BTW, if you're escaping all of these characters for SQL, that's not needed. You
> should
> only need to escape very few, if any, characters.  If you really have to, wait
> to escape it
> until it's needed for the SQL.  No need to clutter up a perfectly good string.
> :-)  Check
> "perldoc DBI" for escaping things and use either DBI's quote method or Perl's q()
> operator when inserting the data. My guess is you'll find that you won't need
> to escape
> much if anything in your strings, making your regex's much easier.
>
> See ya

Thank you!!
This worked:
s+W\\/(.*Pages)+



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

Date: Sat, 1 Feb 2003 14:37:46 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: newbie EASY problem :-)
Message-Id: <slrnb3mg8a.hgu.mgjv@martien.heliotrope.home>

On Sat, 01 Feb 2003 00:10:21 GMT,
	Noerd <n_joeller@sharblbaziilyar.com> wrote:
>> BTW, if you're escaping all of these characters for SQL, that's not
>> needed. You should only need to escape very few, if any, characters.
>> If you really have to, wait  to escape it until it's needed for the
>> SQL.  No need to clutter up a perfectly good string.
>>
>> :-)  Check "perldoc DBI" for escaping things and use either DBI's
>> quote method or Perl's q() operator when inserting the data. My guess
>> is you'll find that you won't need to escape much if anything in your
>> strings, making your regex's much easier.
> 
> Thank you!!
> This worked:
> s+W\\/(.*Pages)+

That is surprising, because it doesn't even compile for me. 

Have you got a magical version of Perl?

What exactly are you replacing with what?

Martien
-- 
                        | 
Martien Verbruggen      | 
                        | In a world without fences, who needs Gates?
                        | 


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

Date: Sat, 01 Feb 2003 05:40:12 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: RFC Date
Message-Id: <3E3B5DB3.81953359@acm.org>

Duke wrote:
> 
> Great, thanks!  Current version:
> 
> use POSIX;
> 
> my $rfcdate = POSIX::strftime('%a, %e %b %Y %X %z', localtime);
> print $rfcdate;

You should use %T or %H:%M:%S (24 hour clock) instead of %X.

my $rfcdate = POSIX::strftime('%a, %e %b %Y %T %z', localtime);



John
-- 
use Perl;
program
fulfillment


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

Date: Fri, 31 Jan 2003 15:04:58 -0800
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: Scope in a format?
Message-Id: <Pine.GSO.4.21.0301311503140.20377-100000@mtwhitney.nsc.com>

On Fri, 31 Jan 2003, Steven Kuo wrote:

> 
> You should use the 2 argument form of 'bless'.  I think in this
> particular case, you might try using a lexically scoped variable to
> hold the value of "reportid" as class data:
> 
> 
> #! /usr/local/bin/perl
> 
> package Foo;
> use strict;
> use warnings;
> 
> my $report_id; # lexically scoped class data
> 
> sub new {
>     my $class = shift;
>     my $self = {};
>     bless $self, $class;
>     return $self;
> }
> 
> sub reportid {
>     my $self = shift;
>     if (@_) {
> 	$self->{reportid} = $report_id = shift;
>     }
>     return $self->{reportid};
> }
> 
> sub print {
>     write;
> }
> 
> format =                                                                        
> @|||||||||    
> $report_id
> .
> 
> 
> 1;
> 
> 
> 


*Slaps self*.  I think I like this better, the accessor (print)
should retrieve and set the class variable before writing:

#! /usr/local/bin/perl

package Foo;
use strict;
use warnings;

my $report_id; # lexically scoped class data

sub new {
    my $class = shift;
    my $self = {};
    bless $self, $class;
    return $self;
}

sub reportid {
    my $self = shift;
    if (@_) {
	$self->{reportid} = shift;
    }
    return $self->{reportid};
}

sub print {
    my $self = shift;
    $report_id = $self->{reportid};
    write;
}

format =                                                                        
@|||||||||    
$report_id
 .


1;

-- 
Regards,
Steven



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

Date: Fri, 31 Jan 2003 20:40:18 -0500
From: Jack Straw <jackstraw@witchita>
Subject: Re: Scope in a format?
Message-Id: <j79m3v8hgqilrtn6mopdrjhhk5f7351jen@4ax.com>

Steven Kuo <skuo@mtwhitney.nsc.com>:

>On Fri, 31 Jan 2003, Jack Straw wrote:
>> I'm working on my first object-oriented module, just for education's
>> sake.  I can set instance data from outside, I can read instance data
>> from outside.  But, for the life of me, I'm having a hard time *using*
>> the instance data from within an object.

>You should use the 2 argument form of 'bless'.  I think in this
>particular case, you might try using a lexically scoped variable to
>hold the value of "reportid" as class data:

WooHoo!  (sp?)

That's the trick Steve, thanks.  It makes perfect sense now that I see
it.  I just didn't notice that particular technique in what I was
reading. (Not that it wasn't actually in there, 'cause I'm sure it
was.)

Now, next trick is to figure out how to code more, when it's a busy
weekend and I have a lot of stuff to do...

Thanks again.
-- 
JackStraw
0x3D561045


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

Date: Fri, 31 Jan 2003 20:42:46 -0500
From: Jack Straw <jackstraw@witchita>
Subject: Re: Scope in a format?
Message-Id: <ec9m3voejt4oiehfbdhhp1d1lq4pcmsc3m@4ax.com>

"Michael Peuser \(h\)" <post@mpeuser.de>:

>"Jack Straw" <jackstraw@witchita> schrieb im Newsbeitrag
>news:3tql3v02v430me1g11ap9e7dugod7lr55o@4ax.com...

>> I'm working on my first object-oriented module, just for education's
>> sake.  I can set instance data from outside, I can read instance data
>> from outside.  But, for the life of me, I'm having a hard time *using*
>> the instance data from within an object.

>Scope! Thats it!
>
>You have to use a variable or whatever that format can "see". It cannot see
>your internal hash references! Because format is a quite old concept you
>have to adapt to it. A class variable should do the trick:

I'm in good shape now, thanks to you and Steve Kuo.  

I really appreciate the time you took.  I work alone, and really
suffer from not having co-workers to talk to and learn from.

Thanks again.

-- 
JackStraw
0x3D561045


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

Date: 31 Jan 2003 23:18:38 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Using split with "df -k"
Message-Id: <slrnb3m12e.ngt.abigail@alexandra.abigail.nl>

Robert Krueger (racsw@frontiernet.net) wrote on MMMCDXL September
MCMXCIII in <URL:news:v3lt14kgral2c3@corp.supernews.com>:
$$   I'm just learning Perl with a couple of new books, but I ran into something 
$$  that i thought should work, but doesn't, and i don't know why.
$$  I'm trying to find out how much space is left on my internal Zip drive, so I 
$$  did this:
$$  
$$  #!/usr/bin/perl -w
$$  
$$  my $Mnt_Point='/mnt/zip';
$$  @Left=split(/ /, `df -k $Mnt_Point`);
$$  print $Left[4];
$$  
$$  The way I understand it, my second line should break up the return from "df 
$$  -k" into separate words separated by spaces, and place them into the array 
$$  @Left.

No. You are splitting on *single spaces*. Between 'Filesystem' and
'1K-blocks', there are a number of spaces. For each space following
the space, the split will return an empty string. So, @Left will
contain 40 to 60 elements, depending on the length of the device file
name, the size of disk, and how much has been used.

What you want is a split on ' ', which will split on a serie of
whitespace. This is documented.



Abigail
-- 
tie $" => A; $, = " "; $\ = "\n"; @a = ("") x 2; print map {"@a"} 1 .. 4;
sub A::TIESCALAR {bless \my $A => A} #  Yet Another silly JAPH by Abigail
sub A::FETCH     {@q = qw /Just Another Perl Hacker/ unless @q; shift @q}


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

Date: Fri, 31 Jan 2003 16:00:25 -0800
From: Ed Kulis <ekulis@apple.com>
Subject: wantnumber? How to tell numeric from string context
Message-Id: <BA604E19.5A6C%ekulis@apple.com>

Hi,

I was just looking in the one hump dromedary book and I noticed the special
variable   $! $OS_ERROR will return different values depending on its string
or numeric context.

All I know is ref $something eq "SCALAR" so how can you get a variable to be
one thing in a numeric context and another in a string context.

I want to use it the same way the $OS_ERROR uses it. I want to call an test
subroutine and return a boolean  0 or not 0 if the sub is called in a
numeric context and a string if the sub was called in a string context.

This would extend what I often do with the wantarray function:

    if (wantarray) { return        @filespecs;}
    else           { return scalar @filespecs;};

This way the caller can ask easily ask "Any files" or "What files".

-ed



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

Date: Sat, 01 Feb 2003 00:17:25 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: wantnumber? How to tell numeric from string context
Message-Id: <x73cn8zwfe.fsf@mail.sysarch.com>

>>>>> "EK" == Ed Kulis <ekulis@apple.com> writes:

  EK> I was just looking in the one hump dromedary book and I noticed
  EK> the special variable $! $OS_ERROR will return different values
  EK> depending on its string or numeric context.

  EK> All I know is ref $something eq "SCALAR" so how can you get a
  EK> variable to be one thing in a numeric context and another in a
  EK> string context.

  EK> I want to use it the same way the $OS_ERROR uses it. I want to
  EK> call an test subroutine and return a boolean 0 or not 0 if the sub
  EK> is called in a numeric context and a string if the sub was called
  EK> in a string context.

Want.pm

or look into overloading.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 4498
***************************************


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