[16965] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4377 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 19 18:10:38 2000

Date: Tue, 19 Sep 2000 15:10: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: <969401422-v9-i4377@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 19 Sep 2000     Volume: 9 Number: 4377

Today's topics:
        Here Document gary.lefko@usafa.af.mil
    Re: Here Document (Jerome O'Neil)
    Re: Here Document <bcaligari@my-deja.com>
    Re: Here Document <tony_curtis32@yahoo.com>
    Re: Here Document <red_orc@my-deja.com>
        Here's a cooTransfer Interrupted <jeffp@crusoe.net>
        How to make a child a parent ? <berube@odyssee.net>
    Re: How to make a child a parent ? <amonotod@netscape.net>
    Re: How to sort a comma delimited file on the Nth field <gellyfish@gellyfish.com>
    Re: Is there a DBI that will connect to MS SQL Server? <gellyfish@gellyfish.com>
    Re: Iterate over greed? (Abigail)
    Re: Join our team <aqumsieh@hyperchip.com>
    Re: Newbie Question - Perlshop and  777 permissions <gellyfish@gellyfish.com>
    Re: Newbie question michaeljgardner@my-deja.com
    Re: Parse::RecDescent: Problem with a Grammar <stephen@twocats.dont-spam.demon.co.uk>
        passing variables to and from scripts potato_salad@my-deja.com
    Re: perl and web <gellyfish@gellyfish.com>
        Perl Threads on Win <iloveyou@mailroom.com>
    Re: Possible to generate html frames from perl ??? <gellyfish@gellyfish.com>
    Re: Possible to generate html frames from perl ??? (Alone)
    Re: Range operator with "... /^$/" <ren.maddox@tivoli.com>
    Re: reading from file <lr@hpl.hp.com>
    Re: reading from file (Abigail)
        Reg-ex Needed akhnaten88@my-deja.com
    Re: Reg-ex Needed <yanick@babyl.sympatico.ca>
        regex help needed <prlawrence@lehigh.edu>
    Re: regexp problem <lr@hpl.hp.com>
        Regular expression for variable substitution jb4mt@my-deja.com
    Re: Regular expression for variable substitution <yanick@babyl.sympatico.ca>
    Re: Regular Expressions: Counting matches? <gellyfish@gellyfish.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 19 Sep 2000 20:45:14 GMT
From: gary.lefko@usafa.af.mil
Subject: Here Document
Message-Id: <8q8j8i$fnb$1@nnrp1.deja.com>

Can you print a here document to a file?  I'm thinking you can ,but the
syntax I use keeps blowing up!
Gary


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


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

Date: Tue, 19 Sep 2000 21:01:35 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: Here Document
Message-Id: <PuQx5.329$JR.269189@news.uswest.net>

gary.lefko@usafa.af.mil elucidates:
> Can you print a here document to a file?  I'm thinking you can ,but the
> syntax I use keeps blowing up!

Use another syntax!

HTH!


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

Date: Tue, 19 Sep 2000 21:06:42 GMT
From: Brendon Caligari <bcaligari@my-deja.com>
Subject: Re: Here Document
Message-Id: <8q8kgg$h7m$1@nnrp1.deja.com>

In article <8q8j8i$fnb$1@nnrp1.deja.com>,
  gary.lefko@usafa.af.mil wrote:
> Can you print a here document to a file?  I'm thinking you can ,but
the
> syntax I use keeps blowing up!
> Gary
-------------
open(XFILE, ">xxx");
print(XFILE << 'EOFILE');

  I'm too sexy for this script
  whatever
EOFILE

close(XFILE);
-------------

I posted a question a few days ago regarding file
handle best practices.  I was recommended (5.6+)
using a scalar value as file handle as follows

open(my $x, ">xxx");
print($x "hello world");
close($x);

How could the here document be used in this case??

Thanks

Brendon


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


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

Date: 19 Sep 2000 16:24:45 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Here Document
Message-Id: <87em2gdqhu.fsf@limey.hpcc.uh.edu>

>> On Tue, 19 Sep 2000 21:06:42 GMT,
>> Brendon Caligari <bcaligari@my-deja.com> said:

> I posted a question a few days ago regarding file handle
> best practices.  I was recommended (5.6+) using a scalar
> value as file handle as follows

> open(my $x, ">xxx"); print($x "hello world"); close($x);

Lose the parentheses, they are somewhat obfuscative...

my $fh;

open $fh, '> OUTPUT' or die ...;

print $fh <<_EOT_;
hello

world
_EOT_

close $fh;

hth
t
-- 
Woo!  A trillion dollar bill.  That's a spicy meatball!
                                         -- Homer Simpson


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

Date: Tue, 19 Sep 2000 21:40:11 GMT
From: Rodney Engdahl <red_orc@my-deja.com>
Subject: Re: Here Document
Message-Id: <8q8mfp$jte$1@nnrp1.deja.com>

In article <8q8j8i$fnb$1@nnrp1.deja.com>,
  gary.lefko@usafa.af.mil wrote:
> Can you print a here document to a file?  I'm thinking you can ,but
> the syntax I use keeps blowing up!
> Gary
>

from what we can see of your script at this point, your error is on
line 17.


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


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

Date: Tue, 19 Sep 2000 17:05:26 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Here's a cooTransfer Interrupted
Message-Id: <Pine.GSO.4.21.0009191704340.29488-100000@crusoe.crusoe.net>

M^q@@;BEGIN{close"stderr"}print+H|R&k,G^w|E,Q&x|c,,,,
M&~i|t,,,q^&q|^^q&l],&^q|jm>|,N|d|A&c,v&q~|~,c^H^C,w&
M|a,qq<\x11A"\x17\x1b\x09Rh\x0d\x0c\x18\x11x>^<<,,,,,
carrier lost

,,;!EOF



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

Date: Tue, 19 Sep 2000 16:46:45 -0400
From: "Neb" <berube@odyssee.net>
Subject: How to make a child a parent ?
Message-Id: <veQx5.140$hs2.6831@news.globetrotter.net>

Hi,

Suppose I got a process that fork a child.  The problem is that the child
will run for a long period of time, way longer than the calling parent.  So,
is there a way to make that child INDEPENDANT from the parent?

For example, this code :

my $pid = fork;
if( $pid == 0 )
{
    sleep(10);
    system('notepad');
    exit(0);
}
elsif( undef $pid )
{
    print 'Process error.';
}
else
{
    print 'Parent process.';
}

It's not what I want.  I want to really make sure the parent can die, and
that the forked "child" process can continue to live without the parent.

Any idea how ?

Thanks,

Neb






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

Date: Tue, 19 Sep 2000 21:27:31 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: How to make a child a parent ?
Message-Id: <8q8ln8$it7$1@nnrp1.deja.com>

In article <veQx5.140$hs2.6831@news.globetrotter.net>,
  "Neb" <berube@odyssee.net> wrote:
<snip>
> is there a way to make that child INDEPENDANT from the parent?
<snip>
>     system('notepad');
<snip>

notepad, huh?  Must be win32... see Win32::Spawn().

amonotod

--
    `\|||/                     amonotod@
      (@@)                     netscape.net
  ooO_(_)_Ooo________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|


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


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

Date: 19 Sep 2000 19:54:28 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: How to sort a comma delimited file on the Nth field?
Message-Id: <8q8cp4$tlf$1@orpheus.gellyfish.com>

On Mon, 18 Sep 2000 12:57:00 -0700 Rob Carraretto wrote:
> Alec Kelingos wrote:
>> 
>> I have a comma delimited file.  e.g.
>> 
>> "alec","10001","42159","michigan"
>> "bob","801","42002","ohio"
>> "fred","55891","42159","oklahoma"
>> 
>> How can I sort this file using the 3rd column and write out to a new file?
>> I can create a hash using the 3rd column as keys and the entire record as
>> the value, then sort the keys and write each element to a new file . is that
>> the best way or is there some other way?
>> 
> 
> The CPAN module Sort::Fields is probably what you want.
> 

ALthough sorting is such a fundamental operation in many programs he will
probably want to see perlfaq4 :

      How do i sort an array by (anything) ?

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

Date: 19 Sep 2000 07:04:01 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Is there a DBI that will connect to MS SQL Server?
Message-Id: <8q6vkh$qa3$1@orpheus.gellyfish.com>

On Mon, 18 Sep 2000 02:37:12 GMT zirconx@my-deja.com wrote:
> Hello. I am looking at hardware and software for a very large
> project, and it looks like I'll have the need to connect to
> a MS SQLServer from Linux/perl. Is this possible? I've tried
> to find the answer but couldn't. I found posts that say it
> should work, might work, does work with 6.5... but can I connect
> to a modern SQLServer (is that like 7.0 or 2000?) via DBD/DBI
> Perl on linux? Which one?
> 

You may be able to use DBD::Sybase or DBD::FreeTDS .

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

Date: 19 Sep 2000 19:07:00 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Iterate over greed?
Message-Id: <slrn8sfe8e.5fq.abigail@alexandra.foad.org>

Keith Arner (karner@fore.com) wrote on MMDLXXI September MCMXCIII in
<URL:news:4FBEA8857476D311A03300204840E1CFCFBC6B-100000@whq-msgusr-02.pit.comms.marconi.com>:
__ 
__ I would like to be able to do:
__ 
__   $_ = 'abc-defgh-ijk-lm-nop';
__ 
__   while ( m/(.*?!)-(.*?!)/g! ) {
__     print "  [$a] [$b]\n";
__   }
__ 
__ ...and get:
__ 
__   [abc-defgh-ijk-lm] [nop]
__   [abc-defgh-ijk] [lm-nop]
__   [abc-defgh] [ijk-lm-nop]  
__   [abc] [defgh-ijk-lm-nop]
__ 
__ Where .*?! and /g! are hypothetical modifiers to make such a thing happen.


    $_ = 'abc-defgh-ijk-lm-nop';
    for (my $i = 0; /^([^-]*(?:-[^-]*){$i})-(.*)/; $i ++) {
        print "[$1] [$2]\n";
    }
    __END__
    [abc] [defgh-ijk-lm-nop]
    [abc-defgh] [ijk-lm-nop]
    [abc-defgh-ijk] [lm-nop]
    [abc-defgh-ijk-lm] [nop]


    $_ = 'abc-defgh-ijk-lm-nop';
    while (/-/g) {
        my $a = substr $_ => 0, $- [0];
        my $b = substr $_ => $+ [0];
        print "[$a] [$b]\n";
    }
    __END__
    [abc] [defgh-ijk-lm-nop]
    [abc-defgh] [ijk-lm-nop]
    [abc-defgh-ijk] [lm-nop]
    [abc-defgh-ijk-lm] [nop]



Abigail
-- 
 :;$:=~s:
-:;another Perl Hacker
 :;chop
$:;$:=~y:;::d;print+Just.$:


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

Date: Tue, 19 Sep 2000 19:36:27 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: Join our team
Message-Id: <7apum0qimb.fsf@merlin.hyperchip.com>


tjla@guvfybir.qlaqaf.bet (Gwyn Judd) writes:

> I was shocked! How could Joe Spammy <joegetty@mediaspam.net>
> say such a terrible thing:
> >Looking spam an spam that spam familiar spam unix spam has spam good
> >understanding spam HTML. spam Knowledge spam regular spam is preferred.
> >You spam be spam charge spam creating spam testing spam files that
> >are spam with spam proprietary software. spam  spam may spam done
> >offsite spam your spam hours. spam Compensation spam consists spam wages and
> >equity spam a spam internet startup.
> >
> >Please e-mail me your resume in either MS Word, HTML, or ASCII format.
> 
> I didn't know ASCII had a format. Alternatively, most HTML and word
> documents are written in ASCII are they not? Ergo this is redundant, I
> could send in my resume in XML and it would be fine do you think?

Well, TeX is ASCII. Send a TeX file and let's see ...

--Ala


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

Date: 19 Sep 2000 21:28:21 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Newbie Question - Perlshop and  777 permissions
Message-Id: <8q8i95$9nh$1@orpheus.gellyfish.com>

On Tue, 19 Sep 2000 16:47:43 GMT Mark Dressel wrote:
> Hi,
> 
> I am trying to set up a perlshop shopping cart, which collects order
> data by writing a temporary file to the server. The directory that
> store this file, temp_orders,  requires 777 acess permissions, but my
> ISP will only allow 755 max. When an order button is pressed perlshop
> responds with the error message "Cannot open temp_orders/258642077 for
> writing" presumably because with only 755 there is no permission to
> write.
> 
> As it is the perlshop.cgi program doing the writing and not the
> customer does the temp_orders directory need 777 permission?
> 

755 is fine as long as the owner of the directory is the same as
the user that the program is running as.

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

Date: Tue, 19 Sep 2000 19:12:48 GMT
From: michaeljgardner@my-deja.com
Subject: Re: Newbie question
Message-Id: <8q8dqr$8sd$1@nnrp1.deja.com>

In article <8q7lbh$9jvu$1@as121.tel.hr>,
  "Silvo" <silvo.vidovic@tel.net.ba> wrote:
> How can I extract the Header and Record size of a DBF file opend in
Perl
> with
> the open statement ?
> Or, this will do it too, how to get the ASCII value of a character?
>
> Please help.
>
> Regards
> Silvo
>
>

Silvo,

I answered this question the first time you asked it.  Plesae check the
responses to your posts prior to re-posting the same question.

Michael


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


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

Date: Tue, 19 Sep 2000 20:56:48 +0100
From: "Stephen Collyer" <stephen@twocats.dont-spam.demon.co.uk>
Subject: Re: Parse::RecDescent: Problem with a Grammar
Message-Id: <969393483.15454.0.nnrp-10.9e98901a@news.demon.co.uk>


Abigail <abigail@foad.org> wrote in message
news:slrn8sd2ff.5fq.abigail@alexandra.foad.org...

> ``
> ``      Function: Identifier ArgList
> ``                    {
> ``                      return { FuncName => $item[1],
> ``                                ArgNames => [ @Args ] };
> ``                    }
>                         ^^^^^^
>
> This is causing you trouble. What you want is:
>
>                       { $return = { FuncName => $item[1],
>                                     ArgNames => [ @Args ] }
>                       }
>
> Or just:
>
>                       { {FuncName => $item[1],
>                          ArgNames => [ @Args ]}
>                       }

Respect is due. This fixes the problem, but I'm baffled.
Surely { return EXPR } and { EXPR } are semantically
equivalent ? I can't see why my original explicit return
should make this fail. As to the $return version, fair
enough, the code can explicitly examine it. OK, Abigail,
spill the beans - why does your version work and mine not ?

Steve Collyer.





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

Date: Tue, 19 Sep 2000 18:53:55 GMT
From: potato_salad@my-deja.com
Subject: passing variables to and from scripts
Message-Id: <8q8cno$7bs$1@nnrp1.deja.com>

Hi, I am wanting to pass information from an entry box to a script to
simply ping a host for example. Can someone please explain how to
  store the info entered into the entry box as a variable and then pass
it to my other script. thanks for any help. Yamar


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


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

Date: 19 Sep 2000 20:03:19 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: perl and web
Message-Id: <8q8d9n$tmj$1@orpheus.gellyfish.com>

On Mon, 18 Sep 2000 15:38:53 -0400 brian d foy wrote:
> In article <39C64B76.8A6D8C5E@shentel.net>, Albert Dewey <timewarp@shentel.net> posted:
> 
>> daud11@hotmail.com wrote:
> 
>> Have you set the permissions to execute only?
> 
>> I set all my scripts to the bare minimum and that is chmod 711 on a unix
>> machine.
> 
> that's not the bare minimum.
> 

100 if you're root and want to execute the file :)

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

Date: Wed, 20 Sep 2000 00:36:51 +0300
From: "iRQ9" <iloveyou@mailroom.com>
Subject: Perl Threads on Win
Message-Id: <8q8m8p$e9c1o$1@ID-51655.news.cis.dfn.de>

Where can I find  Perl for win  with Threads support  ?

I am trying to execute a simple program on ActiveState Perl
_________________________
use Thread;

$thr = new Thread \&sub1;

sub sub1


print "In the thread\n";

}

_________________________

and I am getiing the error:

"No threads in this perl at script line 2."


In the Threads documentation I found some info that says I must recompile
perl
with threads support option. Anybody knows how I can do this in WinNT ?
Is there any other way or place  I can obtain a  "Thread enabled"  Perl for
Win ?


Thanks !







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

Date: 19 Sep 2000 07:28:28 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Possible to generate html frames from perl ???
Message-Id: <8q712c$qdi$1@orpheus.gellyfish.com>

On Mon, 18 Sep 2000 19:01:19 GMT Alone wrote:
> On Sun, 17 Sep 2000 19:47:59 GMT, Sean Malloy <srmalloy@home.com>
> wrote:
> 
>> Alone@Work.com (Alone) wrote:
>>>Is it possible to generate an html frameset without writing to a file?
>> 
>> Certainly. On the website that I administer, I use a Perl script to
>> generate framesets so that the search engine links to properly-framed
>> pages (top banner, left menu, right content) based on the results of
>> searches that locate information in the content pages. Here's the
>> script (once the print statements start, any line _not_ starting with
>> 'print' is wrapped from the previous line until you get to the
>> document close tag):
>> 
> 
<snip code>
> Okay, but correct me if I am wrong, but all your frameset pages
> already exist on your server, so you are just calling them up
> dynamically...  but the framesets *I* need to send the server do not
> previously exist, and I am trying to avoiding creating a file in order
> to do it.
> 
> I can generate html to the browser now without creating an actual
> file.  I want to be able to generate html frames without creating a
> file.  
> 
> My server limits the number of files per user.
> 
> The only way I can determine to generate this page to a browser is to
> first create the framesets as files and generate the html that calls
> them, but this would creates two files...
> 

This really isnt a Perl question at all anymore but simply
a question of program design that would be better asked in
comp.infosystems.www.authoring.cgi.

It would be a fairly trivial matter to take the presented code and alter
it in such a way so that it takes a parameter that indicates which
frame or frameset page should be generated  for example :


#!/usr/bin/perl -w

use strict;
use CGI qw(:standard);
print header;

my $frame = param('frame');

if (not $frame) {
    print frameset();
}
else
{
  print start_html("Frame $frame"),
        h1("This is frame $frame"),
        end_html();
}


sub frameset 
{
    my $script_name = script_name();
    print start_html('Frame Example'),"\n";
    print <<EOHIPPUS;
<FRAMESET COLS="50,50">
   <FRAME SRC="$script_name?frame=1" name="frame1">
   <FRAME SRC="$script_name?frame=2" name="frame2">
</FRAMESET>
EOHIPPUS
    print end_html();
}


/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

Date: Tue, 19 Sep 2000 22:01:03 GMT
From: Alone@Work.com (Alone)
Subject: Re: Possible to generate html frames from perl ???
Message-Id: <39c7a381.3090122@news.reliable-net.net>


Doesn't seem to work...  Frame1 is a pre-written html file, Frame2 is
the cgi call... but when I call it, what the browser gets is the
Frame2 html, and then the frameset html.

Is there anything different I need to do in the Frame2 html
generation?  or do I just generate html as I normally would?




On Mon, 18 Sep 2000 14:29:06 -0600, "Nathaniel Hekman"
<NHekman@geo-slope.com> wrote:

A frameset just points to other urls used to fill each frame.  Make
those
urls point to your cgi script, with some way for the script to know
which
frame it is now generating.  For example, the url to your main page
could be
http://www.whatever.com/myscript.cgi.  myscript.cgi generates a
frameset in
html, saying that frame 1 is to be filled with myscript.cgi?frame=1,
and
frame 2 with myscript.cgi?frame=2.  When myscript.cgi is called with
the
frame parameter set, it generates the appropriate html for that frame.


Nate






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

Date: 19 Sep 2000 14:01:06 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Range operator with "... /^$/"
Message-Id: <m31yygw6j1.fsf@dhcp11-177.support.tivoli.com>

ollie_spencer@my-deja.com writes:

> Yep, I did all the standard things, including using binmode(). See some
> of my earlier replies for my solution(finally!). Seems that chomp()
> only trimmed the \x0a from the end of my NT-stored data, leaving an
> \x0d. Evey line had \x0d in it, even those that appeared empty.

There still seems to be a point of confusion.  Using binmode() is what
makes chomp only trim the \x0a.  Don't use binmode() and you should
get the other behavior.  Here is an excerpt from "perldoc -f binmode":

               Mac OS and all variants of Unix use a single
               character to end each line in the external
               representation of text (even though that single
               character is not necessarily the same across these
               platforms).  Consequently binmode() has no effect
               on these operating systems.  In other systems like
               VMS, MS-DOS and the various flavors of MS-Windows
               your program sees a `\n' as a simple `\cJ', but
               what's stored in text files are the two characters
               `\cM\cJ'.  That means that, if you don't use
               binmode() on these systems, `\cM\cJ' sequences on
               disk will be converted to `\n' on input, and any
               `\n' in your program will be converted back to
               `\cM\cJ' on output.  This is what you want for
               text files, but it can be disastrous for binary
               files.

               Another consequence of using binmode() (on some
               systems) is that special end-of-file markers will
               be seen as part of the data stream.  For systems
               from the Microsoft family this means that if your
               binary data contains `\cZ', the I/O subsystem will
               ragard it as the end of the file, unless you use
               binmode().

So, if you don't use binmode() then you may have a problem with \x1a,
and if you do use binmode() then you will have a problem with
\x0a\x0d.  Assuming you have to contend with the \x1a problem, then
the solution you've already found is probably best.  Otherwise, just
don't call binmode() and the problem goes away.

BTW, I didn't see anyone mention this, and you probably already know
it, but if you ftp the file in binary mode, then the \x0d characters
will not be added (nor the \x1a at the end).

-- 
Ren Maddox
ren@tivoli.com


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

Date: Tue, 19 Sep 2000 11:50:49 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: reading from file
Message-Id: <MPG.14315566ada341da98ad90@nntp.hpl.hp.com>

In article <39c7a928@news.takas.lt> on Mon, 18 Sep 2000 23:43:05 +0200, 
Marvinas <Marvinas@Takas.lt> says...

 ...

> Since I am just starting with perl I have this problem: I want to read an
> integer from a file, but it returns string as an answer. How I could make my
> program return integer?

One of the surprising things about Perl is that strings are converted to 
numbers when they are used as numbers, and numbers are converted to 
strings when they are used as strings.  Automagically.

    print '1' + '1', "\n";  # 2

    print  1  .  1 , "\n";  # 11

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 19 Sep 2000 19:08:02 GMT
From: abigail@foad.org (Abigail)
Subject: Re: reading from file
Message-Id: <slrn8sfead.5fq.abigail@alexandra.foad.org>

Marvinas (Marvinas@Takas.lt) wrote on MMDLXXV September MCMXCIII in
<URL:news:39c7a928@news.takas.lt>:
@@ 
@@     Hello,
@@ 
@@ Since I am just starting with perl I have this problem: I want to read an
@@ integer from a file, but it returns string as an answer. How I could make my
@@ program return integer?


pack()



Abigail
-- 
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'


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

Date: Tue, 19 Sep 2000 19:58:10 GMT
From: akhnaten88@my-deja.com
Subject: Reg-ex Needed
Message-Id: <8q8gg6$c91$1@nnrp1.deja.com>

Okay guys, Please don't send me to an FAQ, as I've perused so many, and
not found my answer... here's the problem:

I need a REGEX to change all commas in a line to a pipe symbol ( | ).
ANY data between <STX> and <ETX> should be ignored though... for
example:

"data1, 5,6,2,<STX>hello, <ETX> my name is Robert, wow <STX>, that is,
neat!!<ETX>,,"

should be changed to:

"data1| 5|6|2|hello,  my name is Robert| wow , that is, neat!!||"

If you could, could you supply one regex that leaves the <STX> and
<ETX> tags in the string, and one that removes them?   I REALLY
appreciate this help!!

--Robert


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


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

Date: Tue, 19 Sep 2000 20:52:08 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: Reg-ex Needed
Message-Id: <YlQx5.273759$1h3.5786624@news20.bellglobal.com>

akhnaten88@my-deja.com wrote:
: Okay guys, Please don't send me to an FAQ, as I've perused so many, and
: not found my answer... here's the problem:

: I need a REGEX to change all commas in a line to a pipe symbol ( | ).
: ANY data between <STX> and <ETX> should be ignored though... for
: example:

: "data1, 5,6,2,<STX>hello, <ETX> my name is Robert, wow <STX>, that is,
: neat!!<ETX>,,"

: should be changed to:

: "data1| 5|6|2|hello,  my name is Robert| wow , that is, neat!!||"

: If you could, could you supply one regex that leaves the <STX> and
: <ETX> tags in the string, and one that removes them?   I REALLY
: appreciate this help!!

$string = "data1, 5,6,2,<STX>hello, <ETX> my name is Robert, ".
          "wow <STX>, that is, neat!!<ETX>,,\n";
 
$with_tags = join '',
             map { y/,/|/ unless /^<STX>.*<ETX>$/; $_ }
             split m/(<STX>.*?<ETX>)/,
             $string;
 
$without_tags = join '',
                map { /^<STX>(.*)<ETX>$/ ? $1 : y/,/|/ && $_ }
                split /(<STX>.*?<ETX>)/,
                $string;
 
print $without_tags;


Joy,
Yanick

-- 
eval" use 'that poor Yanick' ";
print map{ (sort keys %{{ map({$_=>1}split'',$@) }})[hex] }
qw/8 b 15 1 9 10 11 15 c b 13 1 12 b 13 f 1 c 9 a e b 13 0/;


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

Date: Tue, 19 Sep 2000 17:06:40 -0400
From: "Phil R Lawrence" <prlawrence@lehigh.edu>
Subject: regex help needed
Message-Id: <8q8kh2$f9k@fidoii.CC.Lehigh.EDU>

I want a list of all the methods I've used in a directory full of files.

First, I grep'd all the lines out of some files that have '$r->'.

This results in a file full of lines like this:
AIAthletes.pm:$r->add_custom_sql_clause('c_ints','saturn.sorints', @c_ints);
AIAthletes.pm:my $sth_offers_sd = $r->prepare(

What regex can i use to throw out everything except: $r->method_name(@parms)
?

I tried:
#!/usr/local/bin/perl -w
while (<>) {
  print "$_\n";  #before
  s/[^(\$r\->\w+)]//g;
  print "$_\n";  #after
}

Didn't work.  Any help?

Thanks,.
Phil R Lawrence





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

Date: Tue, 19 Sep 2000 12:06:02 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: regexp problem
Message-Id: <MPG.143158faf7cdb2fc98ad92@nntp.hpl.hp.com>

In article <39C75C29.BE49DD79@green-it.com.au> on Tue, 19 Sep 2000 
23:29:29 +1100, Richard Green <richard@green-it.com.au> says...
+ 
+ I'm new to regular expressions, so any help with this is much
+ appreciated to solve this problem, which arises from a script to sort
+ out a web site which was made on Windoze and need to be tidied up
+ before moving to a UNIX system.
+ 
+ 
+ 	$_ = "Some other stuff then ../Dir2/Dir3/File Name.HTML 
+ 	and again ../Dir2/Dir3/File Name.HTML ";
+ 
+ I want to replace the matching right hand side part of the string 
+ 
+ 	"/Dir1/Dir2/Dir3/File Name.HTML" 
+ 
+ with the equivalent right hand side part of 
+ 
+ 	"/dir1/dir2/dir3/file_name.html" 

What does 'right hand side part' mean in relation to these two strings?
 
+ thus  returning $_ as 
+ 
+ 	"Some other stuff then ../dir2/dir3/file_name.html and 
+ 	again ../dir2/dir3/file_name.html "
+ 
+ The two strings used in the substitution are known, and always have
+ the same number of characters, so it is a matter of matching the right
+ most part of the test string and substituting it with a similar number
+ of characters from the right-hand side of the substitution string.
+ 
+ If it isn't possible to substitute using s/// matching and returning
+ the position and length of the substring would be ok.

The biggest problem I see here is delimiting the strings that represent 
the filenames to be modified.  Here is a simple approach that will 
perhaps help you cook up what you are really after:

    s!(\.\./.+\.HTML)\b!(my $x = $1) =~ tr/ A-Z/_a-z/; $x!eg;

+ Thanks & regards
+ 
+ Richard Green
+ In Olympic Sydney 2000

How nice!  It must be hard to pay attention to Perl under those 
circumstances.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 19 Sep 2000 19:43:25 GMT
From: jb4mt@my-deja.com
Subject: Regular expression for variable substitution
Message-Id: <8q8fko$b65$1@nnrp1.deja.com>

Forgive me for not spending hours searching the documentation (no
sarcasm intended: sincerely!), as I am under a severe deadline, and I
am not finding it easy to find information as to how to solve this
problem, either on CPAN or in the Camel book, 3ed.

I'm reading in a template file that contains text equivalent to Perl
variables that are valid in my program; for instance, one line looks
like this:

<td>$emp_data{entity}-$emp_data{location}</td>

I'm trying to write a regular expression to substitute the value of the
actual hash entry from my program.  I thought the following would work:

$line =~ s/\$$&/^\$.*}$/g;

But I'm getting the following error:

"Final $ should be \$ or $name...within string".  I've never had such
an error when trying to use the $ ending anchor before.  I'd love it if
somebody could provide me with one or more of the following:

The correct regular expression for the task;
The reason why what I tried didn't work;
Where within the documentation, very specifically, I might have found
the appropriate information

Thanks in advance!

George


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


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

Date: Tue, 19 Sep 2000 20:24:49 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: Regular expression for variable substitution
Message-Id: <lYPx5.273739$1h3.5783390@news20.bellglobal.com>

jb4mt@my-deja.com wrote:
: Forgive me for not spending hours searching the documentation (no
: sarcasm intended: sincerely!), as I am under a severe deadline, and I
: am not finding it easy to find information as to how to solve this
: problem, either on CPAN or in the Camel book, 3ed.

: I'm reading in a template file that contains text equivalent to Perl
: variables that are valid in my program; for instance, one line looks
: like this:

: <td>$emp_data{entity}-$emp_data{location}</td>

: I'm trying to write a regular expression to substitute the value of the
: actual hash entry from my program.  I thought the following would work:

: $line =~ s/\$$&/^\$.*}$/g;

: But I'm getting the following error:

: "Final $ should be \$ or $name...within string".  I've never had such
: an error when trying to use the $ ending anchor before.  I'd love it if
: somebody could provide me with one or more of the following:

: The correct regular expression for the task;

This will works...

#!/usr/bin/perl
my %substitution = ( name => 'Yanick', answer => 'no', delta => -613  );
 
while(<DATA>)
{
    s/\$\w+(\{\w+\})?/ eval "defined $&" ? eval $& : $& /eg;
    print;
}
__DATA__
Dear $substitution{name},
in answer to your request for a salary increase,
we are pleased to announce you that our answer is
a strong and vibrant '$substitution{answer}'.
Beginning next payday, your salary will show an
increase of $$substitution{delta}. Or, as you
are so fond of saying, $salary += $substitution{delta};
__END__

It applies to scalars and hashes. Extending this to arrays and
slices and all other goodies is an exercise left to the reader.

: The reason why what I tried didn't work;

I'm not sure of the exact reason, but s/\$$&/^\$.*}$/g is
definitively not kosher. Of course, you know that on the right 
side of the regex, '^\$.*}$' means "a caret followed by a dollar
sign followed by a pretty dot followed by a cute star followed
by a closing brace followed by a variable whose name is.. hey!
where's my name! *script dies*"?

: Where within the documentation, very specifically, I might have found
: the appropriate information

I dunno. perldoc perlre will help for the regex, perldoc -f eval and
perldoc -f defined will help for the functions I used...

Joy,
Yanick

-- 
eval" use 'that poor Yanick' ";
print map{ (sort keys %{{ map({$_=>1}split'',$@) }})[hex] }
qw/8 b 15 1 9 10 11 15 c b 13 1 12 b 13 f 1 c 9 a e b 13 0/;


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

Date: 19 Sep 2000 07:38:59 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Regular Expressions: Counting matches?
Message-Id: <8q71m3$qeb$1@orpheus.gellyfish.com>

On 18 Sep 2000 19:54:13 GMT kevin metcalf wrote:
> Chovy wrote:
> 
>>
>> I want to find out how many times a word is matched in a string a text.
>> Basically, I want to count the number of links on a page...
>> ie-
>>
>> ---
>> m/<a href=/ig
>> ---
>>
>> how do I find out how many times it's been matched?
>>
> According to the perl bible (wall, christiansen, schwartz) you would use:
> $nummatches = tr/<a href=/<a href=/ig;
> 

I dont think so.

> or some such similar thing.
> 

please consult the perlop manpage for the difference between tr/// and m///

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

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


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