[15516] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2926 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 2 18:05:47 2000

Date: Tue, 2 May 2000 15:05:22 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <957305122-v9-i2926@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 2 May 2000     Volume: 9 Number: 2926

Today's topics:
    Re: ****Southern Cali Perl Progammer Needed (Tad McClellan)
    Re: [IMPORTANT] Content-type to download an image! (Craig Berry)
    Re: [IMPORTANT] Content-type to download an image! <flavell@mail.cern.ch>
        Aliases for Perl Operators? <none@none.ca>
    Re: bourne 'dot' or csh 'source behavior <keith@streamdata.com>
        Can I undef a whole namespace like undef $Z::temp? blah2163216536126712@my-deja.com
        capture HTML!! ("Daniel Lee")
        DB_File Question <skpurcell@hotmail.com>
    Re: Directory spaces causing problems? <tina@streetmail.com>
        displaying Images <bough_005NOboSPAM@hotmail.com.invalid>
    Re: displaying Images <tina@streetmail.com>
    Re: displaying Images <lauren_smith13@hotmail.com>
    Re: Expect.pm not performing as expected <larkus@my-deja.com>
    Re: Figured it out. <dburch@teleport.com>
    Re: Figured it out. <tina@streetmail.com>
    Re: Figured it out. <sariq@texas.net>
    Re: Figured it out. (Craig Berry)
    Re: Figured it out. <dburch@teleport.com>
    Re: Figured it out. <tina@streetmail.com>
    Re: Figured it out. (Craig Berry)
        global variable with perl-cgi scripts ? <e.bras@hccnet.nl>
        HELP : Script works on Command Line but not as CGI when <carey_bingham@TransCanada.com>
    Re: HELP : Script works on Command Line but not as CGI  (Craig Berry)
        Help with substitution operator. <dburch@teleport.com>
    Re: Help with substitution operator. (Craig Berry)
    Re: Help with substitution operator. <sariq@texas.net>
    Re: How to compare values between 2 arrays ? c_neak@my-deja.com
        How to define my own Perl Operator? <none@none.ca>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 2 May 2000 13:26:18 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: ****Southern Cali Perl Progammer Needed
Message-Id: <slrn8gu3tq.58j.tadmc@magna.metronet.com>

On 2 May 2000 17:58:07 GMT, Mark Badolato <mbadolato@quepasa.com> wrote:
>On 02 May 2000, adan327830@aol.comnospam (ADan327830) wrote in
><20000502130430.10464.00000989@ng-bh1.aol.com>: 
>
>>I am in need of a database management skilled programmer to help
>>finish a personals site (think adultfriendfinder.com)
>>If you think you can design something similar, and have sites that
>>I can take a look at, email me at adan327830@aol.com
>
>
>What is your perl question?


Right.

Like spammers actually read the newsgroups they spew to.

Don't post it. Email it. (or both if you must)


-- 
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Tue, 02 May 2000 20:35:26 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: [IMPORTANT] Content-type to download an image!
Message-Id: <sguf0emr1g2114@corp.supernews.com>

Charles Henry (charles.henry@engineer2k.com) wrote:
: > You can't force a browser to do something from the
: > server-side.  If the client side wants to `view' an
: > image/gif stream then it will, likewise if it wants to
: > `download' it, it will, no matter what you send.
: 
: Absolutely false.
: You should do some CGI !!!

Absolutely true.  Recall that the 'browser' (http client) can be anything
from IE 5 through Lynx through a Perl script I write through me typing
into a telnet session.

Content types are advisory, allowing the client to do something
intelligent with the data when it arrives.  What is intelligent is
entirely up to the client.

: YES I can force the browser to that. That's what headers are made for!!
: That's particularly helpful when you don't want people to link your image!!

Okay, I'm going to hit your site via telnet.  I dare you to make me do
something. :)

: If you can *understand* the following code, you'll know what I mean :

Being snotty is doubly embarrassing when you're wrong. :)

-- 
   |   Craig Berry - cberry@cinenet.net
 --*--  http://www.cinenet.net/users/cberry/home.html
   |   "The road of Excess leads to the Palace
      of Wisdom" - William Blake


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

Date: Tue, 2 May 2000 22:45:50 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: [IMPORTANT] Content-type to download an image!
Message-Id: <Pine.GHP.4.21.0005022225460.10573-100000@hpplus01.cern.ch>

On Tue, 2 May 2000, Charles Henry wrote, quoting some apparently
unnamed informant:

> > You can't force a browser to do something from the
> > server-side. 

Correct, although you can certainly make suggestions.

> > If the client side wants to `view' an
> > image/gif stream then it will, likewise if it wants to
> > `download' it, it will, no matter what you send.

Quite true.

> Absolutely false.
> You should do some CGI !!!

I've been doing it, in a small way, pretty much as long as it has
existed.

> YES I can force the browser to that.

Only in cases where the reader does not know how to circumvent it.

If I configure my browser such that a content-type of
application/download causes it to fire up a diagnostic program, which
evaluates the content of the file and feeds it to an appropriate
viewer, there isn't a darned thing you can do about it.

[...]

> That
> code will prevent most people from hotlinking my logo
            ^^^^^^^^^^^^^^^^^^^

So, in spite of your original claim, you now admit that you cannot
"force" it.

have fun



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

Date: Tue, 2 May 2000 18:03:22 -0300
From: "k" <none@none.ca>
Subject: Aliases for Perl Operators?
Message-Id: <fmHP4.34946$Xk2.127969@tor-nn1.netcom.ca>

Is it possible to assign an "Alias" to an existing Perl Operator?

Example:

# normal use of "eq" operator
$a = 1 if $b eq $c;

# using "same" as an Alias for the "eq" operator
$a = 1 if $b same $c;

The operation is exactly the same,  it's just a different way to call it.

Can this be done?

kh





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

Date: Tue, 02 May 2000 14:00:58 -0600
From: Keith Jones <keith@streamdata.com>
Subject: Re: bourne 'dot' or csh 'source behavior
Message-Id: <390F33FA.D0B6C80E@streamdata.com>

shutchis@sherritt-NO_SPAM_PLEASEintl.com wrote:

> I have some scripts to run non-interactively (cron) and need to establish a
> specific environment. Under sh|ksh I would '. <file>'; in csh 'source <file>'.
> How to get the same behaviour within perl?

The way I handled this was to write a shell script whose responsibility was to
"dot" the setup file, then call my perl script.  It seemed a better solution
than rewriting the setup file in perl (since it could be updated by the vendor
at any time) or play with dotsh.pl that came with my perl distribution.

--
Keith W. Jones, Stream Data Systems Ltd.



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

Date: Tue, 02 May 2000 21:16:08 GMT
From: blah2163216536126712@my-deja.com
Subject: Can I undef a whole namespace like undef $Z::temp?
Message-Id: <8engi8$vkg$1@nnrp1.deja.com>

code
 .
 .
 .
while ($file = readdir(USER)) {

open(IN,"${TEST_PLAN_DIR}template/${user}/${file}")
or warn "cannot open .key file for scheduling:
$!";
 $r = new CGI(IN);
 close(IN);
 $r->import_names('Q');
 .
 .
 .
code

# now I'd like to get rid of the whole namespace Q
because if user 'a' fills out the entire form but
user 'b' leaves some of the fields blank then some
of users 'a' stuff while get mixed up in users 'b'
stuff.



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 2 May 2000 20:14:49 +0100 (BST)
From: daniel_lsl@go.com ("Daniel Lee")
Subject: capture HTML!!
Message-Id: <2000May2.191450.4030@leeds.ac.uk>

Hi is there anyone who can help me out with this.  I used a cgi script to
print out a HTML page.  I would like to add a print feature on it whereby a
user can print the current contents.  Therefore I need to send the HTML page
to another cgi script to parse it.  However I'm not sure how to send the
content of the current HTML page.  Any help would be appreciated.

Daniel




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

Date: Tue, 2 May 2000 16:06:07 -0500
From: "spurcell" <skpurcell@hotmail.com>
Subject: DB_File Question
Message-Id: <390f431c$0$1864@wodc7nh1.news.uu.net>

Hello,
I have the code below, which opens a DB_File., and then I quickly print out
its contents. Which is good and works. But then I add a new key and val, and
reprint it out, but I never seen my new entry?
Why is this, I have been hacking for at least 20 minutes, and it is not
cooperating.

    # we need to open the portfolio hash and deal with it.
    tie (%SN, 'DB_File', "$lbPortfolio/$jobid", O-RDWR, 0777)
        or &squawk("Problems opening the lbPortfolio jobhash to remove the
single entry from the deletion.");
    foreach $key(keys %SN) {
        print "$key and $LB{$key}<br>\n";
    }
    $SN{'scott'} = 'perl5'; # insert the new dittie
foreach $key(keys %SN) {
        print "$key and $LB{$key}<br>\n"; # never see the scott key nor the
perl5 val????????
    }
untie %LB;


Thanks
Scott




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

Date: Tue, 02 May 2000 15:53:35 -0400
From: Tina Mueller <tina@streetmail.com>
Subject: Re: Directory spaces causing problems?
Message-Id: <8enbnu$9eiob$2@fu-berlin.de>

hi,

neo_20001@my-deja.com wrote:

> I have a directory named "School Trips", and my
> CGI script has problems
> writing to it.

maybe you have to put in a backslash to escape the
whitespace:
$file = "School\ Trips";

tina

-- 
        tinamue@gmx.net             |     _   enter the
http://user.berlin.de/~tina.mueller |  __| |___  ___ _ _ ___
--   new: tina's moviedatabase    --| / _` / _ \/ _ \ '_(_-< of
--search & add comments or reviews--| \__,_\___/\___/_| /__/ perception


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

Date: Tue, 02 May 2000 12:12:48 -0700
From: Ian Rogers <bough_005NOboSPAM@hotmail.com.invalid>
Subject: displaying Images
Message-Id: <1ffcfa6b.deaffa74@usw-ex0109-069.remarq.com>

I have created a cgi page which returns information from an
input form. I wanted to display images on my CGI scripts.

I have used the code: print img({-src=>'ani.gif'}); to
display my image on screen but it only loads a box not the
image as it can't find it.

This is proberley the simplest thing but I just can't get
my image to display on the screen.

If anyone could tell me what I am doing wrong I would be
grateful

Ian Rogers


* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping.  Smart is Beautiful


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

Date: Tue, 02 May 2000 15:42:15 -0400
From: Tina Mueller <tina@streetmail.com>
Subject: Re: displaying Images
Message-Id: <8enb2p$9eiob$1@fu-berlin.de>

hi,

Ian Rogers wrote:

> I have used the code: print img({-src=>'ani.gif'}); to
> display my image on screen but it only loads a box not the
> image as it can't find it.

so you print out something like that:
<img src="ani.gif">
in the cgi-script? and the cgi-script is
located in a cg-bin directory? then
the path is wrong, I guess. type in the full path of
the picture.

tina

-- 
        tinamue@gmx.net             |     _   enter the
http://user.berlin.de/~tina.mueller |  __| |___  ___ _ _ ___
--   new: tina's moviedatabase    --| / _` / _ \/ _ \ '_(_-< of
--search & add comments or reviews--| \__,_\___/\___/_| /__/ perception


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

Date: Tue, 2 May 2000 12:46:47 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: displaying Images
Message-Id: <8enbae$mro$1@brokaw.wa.com>


Ian Rogers <bough_005NOboSPAM@hotmail.com.invalid> wrote in message
news:1ffcfa6b.deaffa74@usw-ex0109-069.remarq.com...
>
> I have used the code: print img({-src=>'ani.gif'}); to
> display my image on screen but it only loads a box not the
> image as it can't find it.
>
> If anyone could tell me what I am doing wrong I would be
> grateful

Have you made sure your paths to the images are correct?

Lauren




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

Date: Tue, 02 May 2000 18:04:26 GMT
From: Andrew Crawford <larkus@my-deja.com>
Subject: Re: Expect.pm not performing as expected
Message-Id: <8en5at$iah$1@nnrp1.deja.com>

In article <8ems3c$728$1@nnrp1.deja.com>,
  larkus@my-deja.com wrote:
>
> However -- after I execute this script and do a "df", ain't nothin'
> mounted.



Figured out the problem. So, for the next poor shmoe that it happens to:

$smb->expect(undef)

will prevent the handle from closing before the process finishes.
Apparently, that's what was happening.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 02 May 2000 13:27:44 -0700
From: Dan Burch <dburch@teleport.com>
Subject: Re: Figured it out.
Message-Id: <390F3A40.C7D81AEF@teleport.com>

This worked

         foreach $data_line (@data_line)
                {
                        @nbr = split (/,/, $data_line);
                        $data_line = join ("", @nbr);
                }
 god I love perl.

Dan Burch wrote:

> This is probably an easy one, but I'm new to Perl and I'm having a hard
> time figuring this. I have a txt file with line that contain QTY SOLD
> and then space delimited fields with monthly totals that I can split on.
> The problem is commas in numbers over 1000 like 1,000.  If I just try to
> add up the fields it works for numbers under 1000, but gives a zero
> value for numbers with the comma.  This is what I'm trying:
>
>         elsif (  "$data_line[1]" =~ /QTY SOLD/  )
>         {
>
>          local $year_total = ($data_line[2] +$data_line[3]
> +$data_line[4] +$data_line[5] +$data_line[6] +$data_line[7]
> +$data_line[8] );
>
>                 print DATA_OUT "$year_total,";
>         }
>
> I tried :
>
>   foreach $data_line ( @data_line )
> {
>     $data_line = s/,//;
> }
>
> ahead of getting the total but that doesn't seem to work.
>
> Any Suggestions would be greatly appreciated.
>
> Best Regards
> Dan Burch



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

Date: Tue, 02 May 2000 16:34:06 -0400
From: Tina Mueller <tina@streetmail.com>
Subject: Re: Figured it out.
Message-Id: <8ene3t$995im$3@fu-berlin.de>

Dan Burch wrote:

> This worked
> 
>          foreach $data_line (@data_line)
>                 {
>                         @nbr = split (/,/, $data_line);
>                         $data_line = join ("", @nbr);
>                 }

so you maybe have more than one komma?


 $data_line = s/,//g;

should work then...

tina

-- 
        tinamue@gmx.net             |     _   enter the
http://user.berlin.de/~tina.mueller |  __| |___  ___ _ _ ___
--   new: tina's moviedatabase    --| / _` / _ \/ _ \ '_(_-< of
--search & add comments or reviews--| \__,_\___/\___/_| /__/ perception


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

Date: Tue, 02 May 2000 15:54:39 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Figured it out.
Message-Id: <390F408F.8C6AAA33@texas.net>

Tina Mueller wrote:
> 
> Dan Burch wrote:
> 
> > This worked
> >
> >          foreach $data_line (@data_line)
> >                 {
> >                         @nbr = split (/,/, $data_line);
> >                         $data_line = join ("", @nbr);
> >                 }
> 
> so you maybe have more than one komma?
> 
>  $data_line = s/,//g;
> 
> should work then...

No, it shouldn't and it won't.  You're perpetuating the source of the
problem, which is the use of the assignment operator.

- Tom


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

Date: Tue, 02 May 2000 20:54:44 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Figured it out.
Message-Id: <sgug4kba1g2175@corp.supernews.com>

Dan Burch (dburch@teleport.com) wrote:
: This worked
: 
:          foreach $data_line (@data_line)

This works, but I find using the same name for different variables is a
recipe for 3am migraines. :)

:                 {
:                         @nbr = split (/,/, $data_line);
:                         $data_line = join ("", @nbr);
:                 }
:  god I love perl.

It works, but it's definitely going about it the hard way!

-- 
   |   Craig Berry - cberry@cinenet.net
 --*--  http://www.cinenet.net/users/cberry/home.html
   |   "The road of Excess leads to the Palace
      of Wisdom" - William Blake


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

Date: Tue, 02 May 2000 14:30:23 -0700
From: Dan Burch <dburch@teleport.com>
Subject: Re: Figured it out.
Message-Id: <390F48EF.D7A3B046@teleport.com>

Maybe baby talk, but I hacked it out myself and if worked.  I think?  I'm
still verifying data but it looks right so far.

Craig Berry wrote:

> Dan Burch (dburch@teleport.com) wrote:
> : This worked
> :
> :          foreach $data_line (@data_line)
>
> This works, but I find using the same name for different variables is a
> recipe for 3am migraines. :)
>
> :                 {
> :                         @nbr = split (/,/, $data_line);
> :                         $data_line = join ("", @nbr);
> :                 }
> :  god I love perl.
>
> It works, but it's definitely going about it the hard way!
>
> --
>    |   Craig Berry - cberry@cinenet.net
>  --*--  http://www.cinenet.net/users/cberry/home.html
>    |   "The road of Excess leads to the Palace
>       of Wisdom" - William Blake



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

Date: Tue, 02 May 2000 17:53:59 -0400
From: Tina Mueller <tina@streetmail.com>
Subject: Re: Figured it out.
Message-Id: <8enipm$9foau$1@fu-berlin.de>


> >
> >  $data_line = s/,//g;
> >
> > should work then...
> 
> No, it shouldn't and it won't.  You're perpetuating the source of the
> problem, which is the use of the assignment operator.

oops, i didn't see that...
tried it out on my computer (with =~) ant thought,
well, works fine...

sorry

tina


-- 
        tinamue@gmx.net             |     _   enter the
http://user.berlin.de/~tina.mueller |  __| |___  ___ _ _ ___
--   new: tina's moviedatabase    --| / _` / _ \/ _ \ '_(_-< of
--search & add comments or reviews--| \__,_\___/\___/_| /__/ perception


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

Date: Tue, 02 May 2000 22:02:16 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Figured it out.
Message-Id: <sguk38pk1g247@corp.supernews.com>

Dan Burch (dburch@teleport.com) wrote:
: Maybe baby talk, but I hacked it out myself and if worked.  I think?  I'm
: still verifying data but it looks right so far.

My apologies if I seemed to be putting down your working code; especially
when starting out, getting it working at all is 99% of the battle.  I was
merely suggesting that you might wish to continue investigating other and
simpler paths offered by Perl.  Best of luck!

-- 
   |   Craig Berry - cberry@cinenet.net
 --*--  http://www.cinenet.net/users/cberry/home.html
   |   "The road of Excess leads to the Palace
      of Wisdom" - William Blake


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

Date: Tue, 2 May 2000 22:57:03 +0200
From: "Ed Bras" <e.bras@hccnet.nl>
Subject: global variable with perl-cgi scripts ?
Message-Id: <8enfrn$4u0$1@news.hccnet.nl>

Helllu, can someone tell me a good way to define your global variables, such
that they still exists when the perl-cgi-script is called again ? (without
using any perl-apache module).

For example would it be possible to include a package with variables
defined, such that the variables in the packet still exist after the script
finish running ?

Some advice please,
Ed Bras




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

Date: Tue, 2 May 2000 22:36:58 +0200 
From: Carey bingham <carey_bingham@TransCanada.com>
Subject: HELP : Script works on Command Line but not as CGI when using packages !
Message-Id: <390F3C6A.7869F4FB@TransCanada.com>

I have a script called Survey.pl that has a lot of functions that I
wanted to make available to other common scripts.

I moved all the sub routines into a file called FormWrite.pl and then
issued the require("FormWrite.pl"); command in the calling script.

This works great from the command line, however, when running it as a
CGI, the Web server error logs report this :

[02/May/2000:13:56:32] failure (  263): for host 142.5.18.235 trying to
GET /survey-cgi/employee_survey/survey.pl, cgi-parse-output reports: the
CGI program C:\Perl\bin\Perl.exe did not produce a valid header (program
terminated without a valid CGI header (check for core dump or other
abnormal termination)

Survey.pl is the script which requires FormWrite.pl.

If I put the functions back into the Survey.pl, it works fine as a CGI
with no modifications...

Please, if anyone has any ideas, let me know :)

Thanks,

Carey




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

Date: Tue, 02 May 2000 21:56:24 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: HELP : Script works on Command Line but not as CGI when using packages !
Message-Id: <sgujo8gi1g214@corp.supernews.com>

Carey bingham (carey_bingham@TransCanada.com) wrote:
[snip]
: If I put the functions back into the Survey.pl, it works fine as a CGI
: with no modifications...

My guess:  Your web server doesn't set . (current working dir) to where
the script is run from (common under IIS, for example).  Cure is to
require by absolute (file system, not web) path, or put the absolute path
into @INC.

-- 
   |   Craig Berry - cberry@cinenet.net
 --*--  http://www.cinenet.net/users/cberry/home.html
   |   "The road of Excess leads to the Palace
      of Wisdom" - William Blake


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

Date: Tue, 02 May 2000 12:43:19 -0700
From: Dan Burch <dburch@teleport.com>
Subject: Help with substitution operator.
Message-Id: <390F2FD7.222978F2@teleport.com>

This is probably an easy one, but I'm new to Perl and I'm having a hard
time figuring this. I have a txt file with line that contain QTY SOLD
and then space delimited fields with monthly totals that I can split on.
The problem is commas in numbers over 1000 like 1,000.  If I just try to
add up the fields it works for numbers under 1000, but gives a zero
value for numbers with the comma.  This is what I'm trying:

        elsif (  "$data_line[1]" =~ /QTY SOLD/  )
        {


         local $year_total = ($data_line[2] +$data_line[3]
+$data_line[4] +$data_line[5] +$data_line[6] +$data_line[7]
+$data_line[8] );

                print DATA_OUT "$year_total,";
        }

I tried :

  foreach $data_line ( @data_line )
{
    $data_line = s/,//;
}

ahead of getting the total but that doesn't seem to work.

Any Suggestions would be greatly appreciated.

Best Regards
Dan Burch




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

Date: Tue, 02 May 2000 20:42:53 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Help with substitution operator.
Message-Id: <sgufedqr1g239@corp.supernews.com>

Dan Burch (dburch@teleport.com) wrote:
: This is probably an easy one, but I'm new to Perl and I'm having a hard
: time figuring this. I have a txt file with line that contain QTY SOLD
: and then space delimited fields with monthly totals that I can split on.
: The problem is commas in numbers over 1000 like 1,000.  If I just try to
: add up the fields it works for numbers under 1000, but gives a zero
: value for numbers with the comma.  This is what I'm trying:
: 
:         elsif (  "$data_line[1]" =~ /QTY SOLD/  )

No need to double-quote the left operand above; in fact, it just wastes
time.

:         {
:          local $year_total = ($data_line[2] +$data_line[3]
: +$data_line[4] +$data_line[5] +$data_line[6] +$data_line[7]
: +$data_line[8] );

There are easier ways to write that, such as

  $year_total = 0;
  $year_total += $_ foreach @data_line[2..8];

: I tried :
: 
:   foreach $data_line ( @data_line )
: {
:     $data_line = s/,//;
: }
: 
: ahead of getting the total but that doesn't seem to work.

First, make sure you're doing that before you split the line into fields
as operated on above.  Second, as written, this only substitutes the first
comma.  Third and worst, it's operating on $_, not $data_line; $data_line
ends up with the number of substitutions done on $_.

Either

  $data_line =~ s/,//g;

or (prefered)

  $data_line =~ tr/,//d;

would do what you want -- again, if performed before the split.

-- 
   |   Craig Berry - cberry@cinenet.net
 --*--  http://www.cinenet.net/users/cberry/home.html
   |   "The road of Excess leads to the Palace
      of Wisdom" - William Blake


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

Date: Tue, 02 May 2000 15:50:52 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Help with substitution operator.
Message-Id: <390F3FAC.A6412FB6@texas.net>

Dan Burch wrote:
> 
> This is probably an easy one, but I'm new to Perl and I'm having a hard
> time figuring this. I have a txt file with line that contain QTY SOLD
> and then space delimited fields with monthly totals that I can split on.
> The problem is commas in numbers over 1000 like 1,000.  If I just try to
> add up the fields it works for numbers under 1000, but gives a zero
> value for numbers with the comma.  This is what I'm trying:
> 
>         elsif (  "$data_line[1]" =~ /QTY SOLD/  )

No reason for the double quotes, and you probably want to test for an
exact match with 'eq'.

>         {
> 
>          local $year_total = ($data_line[2] +$data_line[3]
> +$data_line[4] +$data_line[5] +$data_line[6] +$data_line[7]
> +$data_line[8] );

Use 'my', not 'local'.  More details in the FAQ.  And no need for the
parentheses.

Perhaps (for Perl versions >= 5.005):

my $year_total;
$year_total += $data_line[$_] for 1..$#data_line; 

> 
>                 print DATA_OUT "$year_total,";
>         }
> 
> I tried :
> 
>   foreach $data_line ( @data_line )
> {
>     $data_line = s/,//;

The bind operator is '=~', and you should include the 'g' modifier.  A
much more efficient approach is:

$data_line =~ tr/,//d;

> }

You should also be using warnings and the strict pragma.

- Tom


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

Date: Tue, 02 May 2000 21:27:04 GMT
From: c_neak@my-deja.com
Subject: Re: How to compare values between 2 arrays ?
Message-Id: <8enh6l$b7$1@nnrp1.deja.com>

In article <u9zoq8ap1k.fsf@wcl-l.bham.ac.uk>,
  nobull@mail.com wrote:

> FAQ: "How can I tell whether a list or array contains a certain
element?"
>
> > My code in Perl...
>
> ...looks familiar.  You've posted this before.  We've told you what's
> wrong with it before.  You have ignored us.  What point is there in us
> trying to help you?
>

Sorry , nobull ! I've not ignored your good suggestions , and i think
that i've made a great mistake if i don't reply to you !
Sorry again :-(




Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 2 May 2000 17:57:19 -0300
From: "k" <none@none.ca>
Subject: How to define my own Perl Operator?
Message-Id: <AgHP4.34940$Xk2.128483@tor-nn1.netcom.ca>

I would like to create an "in" operator which would test if a value is in an
array.

Here's how it would work:

    $car = "ford";
    @cars = ['toyota','ford'];
    print "something" if $car in @cars;

The subroutine might be this:

sub in {
  my ($val,@list) = @_;

  # check if the value is already in the list
  if (grep $_ eq $val, @list) {return 1;}
  else {return 0;}
}

Essentially it's the same as the following:

    print "something" if &in($car, @cars);

but much cleaner:

    print "something" if $car in @cars;

Is it possible to do this sort of thing without hacking the perl core?

Thanks,
kh






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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 2926
**************************************


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