[16762] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4174 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 30 06:10:33 2000

Date: Wed, 30 Aug 2000 03:10:19 -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: <967630218-v9-i4174@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 30 Aug 2000     Volume: 9 Number: 4174

Today's topics:
    Re: I need help! <taboo@comcen.com.au>
    Re: Is perl powerful enough to create cybermoney? roypdavies@my-deja.com
    Re: Just another silly post. <madings@baladi.bmrb.wisc.edu>
        logparser for fps's <john@tackman.net>
        Looking for help with list element numbering <Jodyman@usa.net>
    Re: Looking for help with list element numbering <bcaligari@my-deja.com>
    Re: Looking for help with list element numbering <wyzelli@yahoo.com>
    Re: making sure input is a certain way i.e. starting an (Keith Calvert Ivey)
    Re: method="get" <timewarp@shentel.net>
    Re: method="get" <mcnultya@NOSPAMnortelnetworks.com>
    Re: method="get" <flavell@mail.cern.ch>
        MySQL Table <ales.romaniuk@zag.si>
    Re: MySQL Table (Hasanuddin Tamir)
        MySQL with Perl notknown@anonymous.com
    Re: MySQL with Perl dnsdev@yahoo.com
    Re: MySQL with Perl <Peter.Dintelmann@dresdner-bank.com>
        perlcc (Marcel Grunauer)
    Re: png/gif format <taboo@comcen.com.au>
    Re: Problems editing text with Perl (Martien Verbruggen)
    Re: Reg Exp Problem - What is wrong with this?? (Daniel Chetlin)
        regex to match (and replace) a control code. <danny@lennon.postino.com>
    Re: replace some word in text file - THANX <ps@sbor.ru>
    Re: replace some word in text file (Keith Calvert Ivey)
    Re: selling perl to management (Daniel Chetlin)
    Re: selling perl to management (Abigail)
    Re: selling perl to management (Daniel Chetlin)
    Re: sorting a hash by key value (I've looked at the TIE nobull@mail.com
        square brackets in HERE documents <ronald_f@my-deja.com>
    Re: square brackets in HERE documents (Marcel Grunauer)
        Trouble setting arrays and hashes in namespace $this_na <superior@island.net>
    Re: Trouble setting arrays and hashes in namespace $thi nobull@mail.com
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 30 Aug 2000 03:56:13 +1100
From: "Kiel Stirling" <taboo@comcen.com.au>
Subject: Re: I need help!
Message-Id: <39abeb2d$1_3@nexus.comcen.com.au>


"Nicola" <nedoac2@tin.it> wrote:
>I'm an Italian programmer.>I'm trying to make a webmail program, but i'm not very expert with perl
>language and so i have some problems.
>The first problem is this:
>I'm searching for an example of a script using the modul Mime::Lite.
>Does somebody can post me a simple to send some text and a file attachment?

Try cpan.org. Do a module search. 

Unless u r doing this to learn, I would just download something like 
IMP or Emu Mail and save my brain cells.


Kiel Stirling



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

Date: Wed, 30 Aug 2000 09:36:26 GMT
From: roypdavies@my-deja.com
Subject: Re: Is perl powerful enough to create cybermoney?
Message-Id: <8oikip$q0f$1@nnrp1.deja.com>

In article <sqoeham6c5d73@corp.supernews.com>,
  cberry@cinenet.net (Craig Berry) wrote:
> pohanl@my-deja.com wrote:
> : The future of money.
>
> I hope said future involves more of it drifting my way. :)
>
> : As we move into the new century, the money system is being changed.
> : The value of currency is now being based on a subjective (demand
> : based) rather than an objective (backed by gold) basis.
>
> Actually, this has been practically true throughout the history of
money
> (since the value of gold is itself subjective), and entirely true for
the
> USA for most of the 20th century (since the gold standard was
abandoned).
>
>

Those of you interested in this topic might be interested in my web site
on the history of money based on a book of the same title by my father,
an emeritus professor of economics. The website has a number of essays,
by myself, on various topics in monetary history, and a detailed,
annotated chronology of significant events spread over 18 web pages, by
my father and myself.

Roy Davies

History of Money from Ancient Times to the Present Day
http://www.ex.ac.uk/~RDavies/arian/llyfr.html


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


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

Date: 30 Aug 2000 05:39:52 GMT
From: Steve Mading <madings@baladi.bmrb.wisc.edu>
Subject: Re: Just another silly post.
Message-Id: <8oi6n8$d56$2@news.doit.wisc.edu>

Rick Delaney <rick.delaney@home.com> wrote:

: Steve Mading wrote:
:> 
:> Abigail <abigail@foad.org> wrote:
:> : Steve Mading (madings@baladi.bmrb.wisc.edu) wrote
:> : ::
:> : :: This is configurable behaviour that can be fixed trivially.  Perl
:> : :: regex's can be told to match $ to end-of-string with a switch.
:> 
:> : You got me there. Can to tell us which switch that is? I can't find
:> : it in man perlrun.
:> 
:> This is from "man perlre", the perl regex page.  In the documentation
:> for the switches you can put at the end of the epression (for example,
:> the /i for case insensitive), there is this /s switch:
:> 
:>        s   Treat string as single line.  That is, change "." to
:>            match any character whatsoever, even a newline, which
:>            it normally would not match.
:> 
:>            The /s and /m modifiers both override the $* setting.
:>            That is, no matter what $* contains, /s without /m
:>            will force "^" to match only at the beginning of the
:>            string and "$" to match only at the end (or just
:>            before a newline at the end) of the string.  Together,
:>            as /ms, they let the "." match any character
:>            whatsoever, while yet allowing "^" and "$" to match,
:>            respectively, just after and just before newlines
:>            within the string.

: This is from "man perlrun".

:    -s    enables rudimentary switch parsing for switches on the
:          command line after the program name but before any filename
:          arguments (or before a --). Any switch found there is
:          removed from @ARGV and sets the corresponding variable in
:          the Perl program. The following program prints "1" if the
:          program is invoked with a -xyz switch, and "abc" if it is
:          invoked with -xyz=abc.

:              #!/usr/bin/perl -s
:              if ($xyz) { print "$xyz\n" }

That's a command-line switch.  I was referring to a regular-expression
switch which might, for example, get used in an expression like so:

      if( $foo =~ /pattern/s ) ...;


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

Date: Wed, 30 Aug 2000 07:36:42 GMT
From: "John Tackman" <john@tackman.net>
Subject: logparser for fps's
Message-Id: <eQ2r5.2592$Av5.72045@news.kpnqwest.fi>

Hello all,

This is an open request for an existing piece of script or for someone to
make one.

I'm planning to create a massive ranking-facility for online
first-person-shooter games and others and for this I need to get a small
piece of perl, If you know something that already does this, please tell me,
if you feel like making it, also tell me =)

function of program:

basically, open all files in specified directory, scan them for data that is
wanted (maybe defined in separate
config file) and store the data in an internal DB, postgres or MySQL.

No other functionality needed, and if you live in Finland and want to do
this for me, I'll buy you a beer =)

--
John




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

Date: Wed, 30 Aug 2000 00:40:29 -0400
From: "Jody Fedor" <Jodyman@usa.net>
Subject: Looking for help with list element numbering
Message-Id: <8oi35h$daq$1@plonk.apk.net>

The following program produces a list of filenames from a transfer.log file.
I find the unique file names but would like to count the number of times
these files are found in the log.  I don't know a good way to do this.  Any
help?

(Would like an output similar to:
index.htm 6
toner.htm 12
inkjet.htm 8  etc. etc. etc. )

Thank you.

#!c:\perl -w

open (INFILE,"c:\\perl\\logs\\transfer.log") || die "Can't read
transfer.log: $!";
print "reading transfer1.log\n";

while (<INFILE>) {
  $record = $_;
  chomp $record;
$html = $record;
$html =~ s/.*] "GET \/cgi-bin\/serve.pl\/\d+\/(.*\.htm) .*/$1\n/;
if (length $html < 30) {$files .= $html;}
}

close (INFILE);

my @list = ($files =~ /\w+\.htm/g);  #list of all files
@sortlist = sort @list;

%seen = ();
foreach $item (@sortlist) {
 $seen{$item}++;
 }
@uniq = keys %seen;        # as found in Perl Cookbook Chapter 4.6
@suniq = sort @uniq;
foreach $uniq (@suniq) {print "$uniq\n"};





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

Date: Wed, 30 Aug 2000 05:25:28 GMT
From: Brendon Caligari <bcaligari@my-deja.com>
Subject: Re: Looking for help with list element numbering
Message-Id: <8oi5rr$9ik$1@nnrp1.deja.com>

In article <8oi35h$daq$1@plonk.apk.net>,
  "Jody Fedor" <Jodyman@usa.net> wrote:
> The following program produces a list of filenames from a
transfer.log file.
> I find the unique file names but would like to count the number of
times
> these files are found in the log.  I don't know a good way to do
this.  Any
> help?
>
> (Would like an output similar to:
> index.htm 6
> toner.htm 12
> inkjet.htm 8  etc. etc. etc. )
>

[snip snip]

> %seen = ();
> foreach $item (@sortlist) {
>  $seen{$item}++;
>  }
> @uniq = keys %seen;        # as found in Perl Cookbook Chapter 4.6
> @suniq = sort @uniq;
> foreach $uniq (@suniq) {print "$uniq\n"};

I have tried the following code (counting 'unique' elements in array
@arr instead and it has worked pretty well for me.

my @arr =('sue', 'anne', 'sue', 'sue', 'mary', 'anne');
my %counthash = ();

# counting occurances
foreach (@arr)	{
	$counthash{$_}++;
}

# printing them out
my ($key, $value);
while (($key, $value) = each(%counthash))	{
	print("$key\t$value\n");
}

# another way of printing them out
foreach (sort(keys(%counthash)))	{
	print("$_\t$counthash{$_}\n");
}

While this works, I would appreciate some comments on 'incrementing' a
hash value that might not have been initialised.  Should I just '++
increment' or should I check for the existence of that hash key?
 ..say,

if (exists($counthash{$_})) { $counthash{$_}++; }
else { $counthash{$_} = 1; }

Brendon



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


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

Date: Wed, 30 Aug 2000 18:04:16 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Looking for help with list element numbering
Message-Id: <SF3r5.4$84.928@vic.nntp.telstra.net>

"Brendon Caligari" <bcaligari@my-deja.com> wrote in message
news:8oi5rr$9ik$1@nnrp1.deja.com...
>
> While this works, I would appreciate some comments on 'incrementing' a
> hash value that might not have been initialised.  Should I just '++
> increment' or should I check for the existence of that hash key?
> ..say,
>
> if (exists($counthash{$_})) { $counthash{$_}++; }
> else { $counthash{$_} = 1; }
>

Autoincrementing an undefined variable is a perfectly acceptable way of
setting it to a value.  This is one of the 'magic' things about Perl.

Wyzelli




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

Date: Wed, 30 Aug 2000 03:45:27 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: making sure input is a certain way i.e. starting and ending  with double quotes
Message-Id: <39b28253.14429442@news.newsguy.com>

arthur <star@sonic.net> wrote:

>> my($cgi) = CGI->new();
>> if($cgi->param('name') !~ /^\".+\"$/){
>> print $cgi->header(),
>> $cgi->start_html(),
>> $cgi->p('Oi goober, I said within " " :p'),
>> $cgi->end_html();
>> }
>> 
>> Btw, if you're testing this on the command line, you'll need to put the "'s
>> in as %22 (name=%22bob%22) Otherwise CGI.pm will strip them off (It confused
>> me:)
>> 
>
>Thanks when I put that in I get --  CGI=HASH(0x81d8bd8)Content-Type:
>text/html 
>Oi goober, I said within " " :p

You must have gotten more than that.  What happened to
start_html() and the <P> tag?  In any case, the first part
indicates that you've printed the CGI object itself rather than
using a method.  Could you perhaps have typed $cgi=>header()
instead of $cgi->header() above?

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


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

Date: Wed, 30 Aug 2000 00:15:18 -0400
From: Albert Dewey <timewarp@shentel.net>
Subject: Re: method="get"
Message-Id: <39AC8A56.9F4F2022@shentel.net>

Bart Lateur wrote:

> Tony L. Svanstrom wrote:
>
> >No, you don't search for a module when all you want is
> >$ENV{'QUERY_STRING'}
>
> Most of the time, and in the general case, you need to decode the string
> as well. There's where all the cargo cult code (s/%(..)/pack 'c', hex
> $1/ge, anyone?) comes in. A module is better for this, making sure you
> get it right. Even Steve Brenner's old cgi-lib.pl is better for this.
> But I do think that CGI.pm is overkill. I never need it to generate HTML
> anyway (I always use template mechanisms, or here-docs for single
> pages), so the bulk of it is ballast.
>
> --
>         Bart.

I have to agree with Bart in that CGI.pm is way more than I need. I too use
templates for my html and forms. Much easier for me to deal with as I am
totally fluent with html and my pages are always tables nested in tables
within tables and the only way you can get the look I use is with straight
html written in notepad. For my menus, data, and content I use place markers
(typically $Content for the main content, etc...) and use Perl to stuff my
templates with whatever is needed at the time. The part of CGI.pm I do take
full advantage of is in the parsing of the uploaded data from my forms. This
really makes life simpler for this chore. Just a side comment from the
peanut gallery . . . .

Albert Dewey

--
$Sig = "Jfhg&Amlgsvi&Pvio&Hzxpvi";
$Sig =~ tr/abcdefghijklmnopqrstuvwxyz&/zyxwvutsrqponmlkjihgfedcba /;
print $Sig;




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

Date: 30 Aug 2000 09:27:53 GMT
From: Antony <mcnultya@NOSPAMnortelnetworks.com>
Subject: Re: method="get"
Message-Id: <8oik2p$jo4$1@qnsgh006.europe.nortel.com>

tony@svanstrom.com (Tony L. Svanstrom) wrote:
>Antony <mcnultya@NOSPAMnortelnetworks.com> wrote:
>
>> "Erik" <e.hofstra@student.utwente.nl> wrote:
>> >How can i read the values from a form that is sent
>> >with method="get" in Perl?
>
>> Try this :
>> 
>> read(STDIN, $incoming, $ENV{'CONTENT_LENGTH'});
>> 
>> Reads the info into $incoming
>> That's the easiest way I know. Anyone know of an easier way ?
>
>I don't understand how you can think that that's an easy way to get
>get-values, when what it does is taking posted values...
>

I always get the two mixed up :o)

>
>     /Tony
>-- 
>     /\___/\ Who would you like to read your messages today? /\___/\
>     \_@ @_/  Protect your privacy:  <http://www.pgpi.com/>  \_@ @_/
> --oOO-(_)-OOo---------------------------------------------oOO-(_)-OOo--
>   on the verge of frenzy - i think my mask of sanity is about to slip
> ---ôôô---ôôô-----------------------------------------------ôôô---ôôô---
>    \O/   \O/  ©99-00 <http://www.svanstrom.com/?ref=news>  \O/   \O/



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

Date: Wed, 30 Aug 2000 11:38:09 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: method="get"
Message-Id: <Pine.GHP.4.21.0008301128550.12815-100000@hpplus03.cern.ch>

On Wed, 30 Aug 2000, Bart Lateur wrote:

> But I do think that CGI.pm is overkill.

It's a point of view, but some of the alternatives turn out to be
worse.  Don't overlook CGI.pm's use of autoloading.

> I never need it to generate HTML anyway (I always use template
> mechanisms, or here-docs for single pages),

Mostly I find myself doing the same.  But at least I know I'm
not designing myself into a dead-end.

> so the bulk of it is ballast.

Programming anything by means of the CGI interface, and having to
spawn off a new task for any request, is a tremendous ballast.  
Nevertheless, for pilot implementations and low-usage tasks it can be
the right solution.  

If you're worried about the efficiency of your server-side processing,
then I'd say CGI.pm - and indeed programming the task in Perl at all -
is amongst the less significant things to worry about.

Important principle of program design, if you'll excuse me for stating
the obvious, is not to spend effort optimising the wrong thing.

all the best



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

Date: Wed, 30 Aug 2000 08:40:58 +0200
From: Marvin <ales.romaniuk@zag.si>
Subject: MySQL Table
Message-Id: <MPG.1416cae8686f972d989682@news.siol.net>

Hi !

Can anyone tell me, how to obtain information about table into Perl.
I would like to know field name, field type, size, is it key etc..

Thanks
Marvin


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

Date: Wed, 30 Aug 2000 21:52:02 GMT
From: hasant@trabas.co.id (Hasanuddin Tamir)
Subject: Re: MySQL Table
Message-Id: <slrn8qpfjo.dba.hasant@borg.intern.trabas.co.id>

On Wed, 30 Aug 2000 08:40:58 +0200, ales.romaniuk@zag.si wrote:
> Hi !
> 
> Can anyone tell me, how to obtain information about table into Perl.
> I would like to know field name, field type, size, is it key etc..

One or two of these modules can help you,

    DBI.pm
    DBD::mysql.pm
    Mysql.pm

HTH
san
-- 
trabasLabs * hasant@trabas.com * http://www.trabas.com
Zero Point * hasant@zp.f2s.com * http://www.zp.f2s.com


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

Date: Wed, 30 Aug 2000 00:56:30 -0400
From: notknown@anonymous.com
Subject: MySQL with Perl
Message-Id: <39AC93FD.8D7FBF43@anonymous.com>

i really need a simple script or some code bits that would help me to
create a MySQL database.

thanks in advance



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

Date: Wed, 30 Aug 2000 07:35:07 GMT
From: dnsdev@yahoo.com
Subject: Re: MySQL with Perl
Message-Id: <qrdpqs4p3r12pu1hmumidnio818vnj113r@4ax.com>

Ask your web admin to create you a database , you would use perl to
add tables and rows to that database. You have to be more specific in
your questions , are you trying to create the tables and columns or
are you trying to populate the tables with data?





On Wed, 30 Aug 2000 00:56:30 -0400, notknown@anonymous.com wrote:

>i really need a simple script or some code bits that would help me to
>create a MySQL database.
>
>thanks in advance



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

Date: Wed, 30 Aug 2000 10:35:54 +0200
From: "Dr. Peter Dintelmann" <Peter.Dintelmann@dresdner-bank.com>
Subject: Re: MySQL with Perl
Message-Id: <8oih1r$d591@intranews.bank.dresdner.net>

    Hi,

notknown@anonymous.com schrieb in Nachricht
<39AC93FD.8D7FBF43@anonymous.com>...
>i really need a simple script or some code bits that would help me to
>create a MySQL database.

    I dont't know why you consider this a perl problem...
    Have a look at the docu in
    http://www.mysql.com/documentation/index.html

        Peter





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

Date: Wed, 30 Aug 2000 09:12:59 GMT
From: marcel@codewerk.com (Marcel Grunauer)
Subject: perlcc
Message-Id: <slrn8qpk09.dqh.marcel@gandalf.local>


I'm trying to get perlcc to compile even the smallest of test programs,
and have been trying ever since perlcc appeared, but never got anywhere
at all.


$ cat hello.pl
#!/opt/perl/bin/perl

print "hello world!";


$ perlcc -o hello hello.pl
--------------------------------------------------------------------------------
Compiling hello.pl:
--------------------------------------------------------------------------------
Making C(hello.pl.c) for hello.pl!
perl -I/home/marcel/lib/perl -I/opt/perl/lib/5.6.0/i686-linux
-I/opt/perl/lib/5.6.0 -I/opt/perl/lib/site_perl/5.6.0/i686-linux
-I/opt/perl/lib/site_perl/5.6.0 -I/opt/perl/lib/site_perl -I. -MB::Stash
-c  hello.pl
perl -I/home/marcel/lib/perl -I/opt/perl/lib/5.6.0/i686-linux
-I/opt/perl/lib/5.6.0 -I/opt/perl/lib/site_perl/5.6.0/i686-linux
-I/opt/perl/lib/site_perl/5.6.0 -I/opt/perl/lib/site_perl
-I. -MO=C,-umain,-uattributes,-uDB hello.pl
Starting compile
Walking tree
Prescan
Saving methods
Bootstrap attributes hello.pl
Writing output
Loaded B
Loaded IO
Loaded Fcntl
hello.pl syntax OK
Compiling C(hello) for hello.pl!
perl -I/home/marcel/lib/perl -I/opt/perl/lib/5.6.0/i686-linux
-I/opt/perl/lib/5.6.0 -I/opt/perl/lib/site_perl/5.6.0/i686-linux
-I/opt/perl/lib/site_perl/5.6.0 -I/opt/perl/lib/site_perl
-I. /tmp/hello.pl.tst
cc -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64  -I/opt/perl/lib/5.6.0/i686-linux/CORE -o hello
hello.pl.c   -L/usr/local/lib -L/opt/perl/lib/5.6.0/i686-linux/CORE
-lperl -lnsl -lndbm -lgdbm -ldbm -ldb -ldl -lm -lc -lposix
-lcrypt /opt/perl/lib/5.6.0/i686-linux/auto/IO/IO.so
/opt/perl/lib/5.6.0/i686-linux/auto/Fcntl/Fcntl.so
/tmp/ccoEF1hq.o: In function `xs_init':
/tmp/ccoEF1hq.o(.text+0x347c): undefined reference to `boot_DynaLoader'
collect2: ld returned 1 exit status
ERROR: In compiling code for hello.pl.c !


Which library is it missing?

The situation is not much better with the latest developer release
(which probably shouldn't be discussed here, but I mention it anyway
since it's related):


$ /opt/devperl/bin/perlcc -o hello hello.pl
/opt/devperl/bin/perlcc: hello.pl did not compile, which can't happen:
perl: error in loading shared libraries:
/opt/devperl/lib/5.7.0/i686-linux-thread-multi/auto/B/B.so: undefined
symbol: Perl_Tstack_sp_ptr


Does anyone use perlcc? At all? With any mentionable results?


--
Marcel Gr\"unauer - Codewerk plc . . . . . . . . . . . <http://www.codewerk.com>
Perl Consulting, Programming, Training, Code review . . .  <marcel@codewerk.com>
sub AUTOLOAD{($_=$AUTOLOAD)=~s;^.*::;;;y;_; ;;print} Just_Another_Perl_Hacker();


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

Date: 30 Aug 2000 04:11:03 +1100
From: "Kiel Stirling" <taboo@comcen.com.au>
Subject: Re: png/gif format
Message-Id: <39abeea7_2@nexus.comcen.com.au>


"Ivan Murray" <imurray@wel.co.nz> wrote:
>I'm playing with Multi Router Traffic Grapher (www.mrtg.org) and it seems>perl is producing PNG and GIF files incorrectly. It outputs an html file
>with graphs. When you view the html in a browser, the graphs dont load and
>the progress bar does not move. When you get the properties of the graph
>placeholder within the browser, it reports the size as -1.
>
>Any ideas?
>
>Cheers
>Ivan
>
>

Maybe try writing the gifs to file first????

-Kiel Stirling


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

Date: Wed, 30 Aug 2000 18:57:11 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Problems editing text with Perl
Message-Id: <slrn8qpfin.ucf.mgjv@martien.heliotrope.home>

On Tue, 29 Aug 2000 23:47:36 GMT,
	itgirl57@my-deja.com <itgirl57@my-deja.com> wrote:
> In article <MPG.1415b75dd0f5cab98acf3@nntp.hpl.hp.com>,
>   Larry Rosler <lr@hpl.hp.com> wrote:
> >
> >     perl -pi -e 's/abc/def/g' filename
> 
> This works in a command line, but not within a script, which is where I
> need it.  Also, the -e option doesn't seem to work with Solaris 2.5.1.
> However, the faq had another suggestion, which I use below.

The -e option most definitely does work on Solaris 2.5.1, and other
versions of Solaris as well. In sh, ksh, tcsh and csh. Maybe you
mistakenly tried

# perl -pie 'perl code'

man perlrun will tell you that the i option expects an argument, which
is why you can't do that.

> This WORKS, but it seems like a convoluted way to get such a simple
> thing done.  I can do basically the same thing with just three lines in
> a shell script using sed.  Do you know of a better way to do this in
> Perl?

As a 'program'
$ cat foo
#!/usr/local/bin/perl -wpi
s/abc/def/g
$ cat bar
123456/abc
123456/abc
123456/abc
123456/abc
$ ./foo bar
$ cat bar
123456/def
123456/def
123456/def
123456/def

As a shell script
$ cat fee
#!/bin/sh
perl -wpi -e 's/abc/def/g' $*
$ ./fee bar

For something as trivial as that, it hardly matters what you use; sed or
perl. Pick whatever tickles your fancy. But saying that 'in a shell
script with sed I can do it shorter' isn't true, simply because 'in a
shell script with perl' it's as short as it more or less gets. And in a
perl script, it's slightly shorter.

If you want to code the name of the file in the script:
$ cat foo2
#!/usr/local/bin/perl -wpi
BEGIN{@ARGV = qw(bar)}
s/abc/def/g

Martien
-- 
Martien Verbruggen              | My friend has a baby. I'm writing
Interactive Media Division      | down all the noises the baby makes
Commercial Dynamics Pty. Ltd.   | so later I can ask him what he meant
NSW, Australia                  | - Steven Wright


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

Date: Wed, 30 Aug 2000 05:30:04 GMT
From: daniel@chetlin.com (Daniel Chetlin)
Subject: Re: Reg Exp Problem - What is wrong with this??
Message-Id: <wZ0r5.10278$D7.460100@news-west.usenetserver.com>

On Tue, 29 Aug 2000 11:39:26 GMT,
 Scott <shamilton@plateausystems.holdthespam.com> wrote:
>I am writing a filter to look for specific strings in submitted
>textarea fields, specifically HTTP links (thanks to all who helped with
>that one) and also email addresses, to turn into mailto links.

Quick answer: URI::Find and Email::Find are your friends.

>Here's the problem: under certain circumstances, and I'm not sure
>exactly what those are, when the following regular expression is
>evaluated, the Perl script seems to bomb out (all I get is an HTTP 500
>response):
>
>s!((?:[\w\-]*\.?)+\@(?:[\w\-])+(?:\.[\w\-]+)*)
> !<a>href="mailto:$1">$1</a>!xig

However, I'm curious about this. What's the output of perl -v for you,
and could you give me an example of a circumstance when it does hang? I
played with it a bit under 5.005_03, AP616, and bleadperl, and wasn't
able to produce a hang. I probably wasn't coming up with the right kind
of input, but I tried several tricks that I thought would work.

The problem (I think) is that you have several places in that REx that
are governed by both a * and a + (I'm hoping Ilya will step in here and
smack me if I'm wrong) so during a non-match the engine has to keep
trying different ways to partition out characters to the * and the +.

But everything I tried was handled easily by Ilya's optimizations, so
I'm really curious as to the specific case that does make it hang.

-dlc




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

Date: 30 Aug 2000 05:32:34 GMT
From: <danny@lennon.postino.com>
Subject: regex to match (and replace) a control code.
Message-Id: <8oi69i$hvu$1@lennon.postino.com>

User-Agent: tin/1.4.2-20000205 ("Possession") (UNIX) (Linux/2.2.14-5.0 (i586))

I am having trouble generating a regex to find an unknown control code.
I have somehow got a control code embedded into some data, but am not
sure what the code is, or how to match & replace it.If I do a cut and
paste of the control code into my s/\code/ /g it works, but I would 
like something a little more generic.

-- 
Danny Aldham     Providing Certified Internetworking Solutions to Business
www.postino.com  E-Mail, Web Servers, Web Databases, SQL PHP & Perl


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

Date: Wed, 30 Aug 2000 12:00:13 +0400
From: "Serg Piskarev" <ps@sbor.ru>
Subject: Re: replace some word in text file - THANX
Message-Id: <967622588.712282@meria.sbor.ru>

Hi All
Thanx for your assistance
The problem is solved
______________
Sergey Piskarev
ps@sbor.ru
ICQ#29477987
Serg Piskarev <ps@sbor.ru> wrote in message
news:967545642.11620@relay2.sbor.ru...
> sorry for stupid question
> Is it possible to replace some word directly in text file (without coping
> file content to an array)?
> Thanx
> ______________
> Sergey Piskarev
> ps@sbor.ru
>
>
>




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

Date: Wed, 30 Aug 2000 03:38:13 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: replace some word in text file
Message-Id: <39b17f1d.13607472@news.newsguy.com>

Albert Dewey <timewarp@shentel.net> wrote:

> open(FILE,"<file.txt") or print "ERROR: 404<br>Cannot open file because
>$!<br>";

Why 404?  This isn't a CGI program, and even if it were script
errors aren't 404 errors.

> while(<FILE>)
>    {
>    $File .= $_ if $. >= 0
>    }
> close (FILE);

That's a new way to do it.  Usually Perl newbies do something
like

    @lines = <FILE>;
    $File = join '', @lines;

But the normal Perl idiom for slurping a whole file would be

    { local $/; $File = <FILE>; }

Of course, since a word isn't going to span lines, it's probably
better to process the file a line at a time, writing a copy to a
temp file, rather then reading the whole file into memory.  You
can rename the temp file when you're done.  Writing a separate
file also keeps you from losing all your data if the program
crashes.  And that's what Brendon Caligari was suggesting in the
post you followed up to.

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


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

Date: Wed, 30 Aug 2000 07:14:36 GMT
From: daniel@chetlin.com (Daniel Chetlin)
Subject: Re: selling perl to management
Message-Id: <wv2r5.10528$D7.475259@news-west.usenetserver.com>

On 27 Aug 2000 16:15:06 GMT, Tina Mueller <tina@streetmail.com> wrote:
>Olivier Dehon <o_dehon@my-deja.com> wrote:
>> In string, @%s now must be written as \@%s
>>
>>      (F) It used to be that Perl would try to guess whether you
>>      wanted an array interpolated or a literal @. ...
>
>but it doesn't produce an error if it isn't
>ambiguous:
>
>|          Now strings are parsed at compile time, and ambiguous
>|          instances of @ must be disambiguated, either by
>|          prepending a backslash to indicate a literal, or by
>|          declaring (or using) the array within the program
>|          before the string (lexically).  (Someday it will
>|          simply assume that an unbackslashed @ interpolates an
>|          array.)
>
>so "this @ would now work, but not name@email.com";

And now (i.e. bleadperl, soon-to-be 5.7.0, what will eventually be
5.6.1, and beyond):

[~] $ perl55 -v

This is perl, version 5.005_03 built for i686-linux

Copyright 1987-1999, Larry Wall

[~] $ perl55 -le'print "foo@bar.com"'
In string, @bar now must be written as \@bar at -e line 1, near
"foo@bar"
Execution of -e aborted due to compilation errors.
[~] $ perl57 -v

This is perl, v5.7.0 built for i686-linux
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2000, Larry Wall

[~] $ perl57 -le'print "foo@bar.com"'
foo.com
[~] $

See MJD's excellent page on this at:

http://www.plover.com/~mjd/perl/at-error.html

-dlc




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

Date: 30 Aug 2000 08:36:47 GMT
From: abigail@foad.org (Abigail)
Subject: Re: selling perl to management
Message-Id: <slrn8qphre.bbg.abigail@alexandra.foad.org>

Daniel Chetlin (daniel@chetlin.com) wrote on MMDLVI September MCMXCIII in
<URL:news:wv2r5.10528$D7.475259@news-west.usenetserver.com>:
&& 
&& And now (i.e. bleadperl, soon-to-be 5.7.0, what will eventually be
&& 5.6.1, and beyond):


No. 5.7.0 will *not* be 5.6.1. 5.6.1 will not have any new development.
If 5.7.0 would become 5.6.1, there wouldn't be much of point of having
a separate development branch, would there? And then, 5.6.x would never
become anywhere near "stable".



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


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

Date: Wed, 30 Aug 2000 09:45:46 GMT
From: daniel@chetlin.com (Daniel Chetlin)
Subject: Re: selling perl to management
Message-Id: <eJ4r5.11035$D7.491524@news-west.usenetserver.com>

On 30 Aug 2000 08:36:47 GMT, Abigail <abigail@foad.org> wrote:
>Daniel Chetlin (daniel@chetlin.com) wrote on MMDLVI September MCMXCIII in
><URL:news:wv2r5.10528$D7.475259@news-west.usenetserver.com>:
>&& 
>&& And now (i.e. bleadperl, soon-to-be 5.7.0, what will eventually be
>&& 5.6.1, and beyond):
>
>
>No. 5.7.0 will *not* be 5.6.1. 5.6.1 will not have any new development.
>If 5.7.0 would become 5.6.1, there wouldn't be much of point of having
>a separate development branch, would there? And then, 5.6.x would never
>become anywhere near "stable".

I understand that -- I was just unclear, I guess. What my statement
above was intended to mean was that it will be true both for 5.7.0 and
5.6.1, not that they can be equated. In other words, I intended my list
to be four separate entities (bleadperl current; 5.7.0 (which doesn't
really exist yet); 5.6.1 (which _really_ doesn't exist yet); and
beyond).

(I realize that no real decisions have been made about 5.6.1 yet, but
I'm going by what MJD said in his at-error page, and assuming there was
a good reason for it. And not seeing any reason why this change wouldn't
go into 5.6.1)

Hope that makes it clearer.

-dlc




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

Date: 30 Aug 2000 08:56:12 +0100
From: nobull@mail.com
Subject: Re: sorting a hash by key value (I've looked at the TIE functions and I'm still confused...)
Message-Id: <u9vgwjw2wn.fsf@wcl-l.bham.ac.uk>

"Dr. Peter Dintelmann" <Peter.Dintelmann@dresdner-bank.com> writes:

> Eric White schrieb in Nachricht <8obb68$et8$1@news.doit.wisc.edu>...
> >I'm using CGI.pm and one thing I'm trying to do is use a hash for my values
> >and labels in a checkbox_group form.  Everything works, but now I'd like to
> >have the labels displayed in the value order, not the default order of the
> >hash.  I'm not sure how to do this.
> 
>     so you are facing a sorting problem, right?

Wrong.

This is not a question about sorting but rather about the API of
CGI::checkbox_group() (and as such is answered by reading about
checkbox_group() in perldoc CGI).

Eric has posted this exact same question before.  Please stop it Eric.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Wed, 30 Aug 2000 09:12:10 GMT
From: Ronny <ronald_f@my-deja.com>
Subject: square brackets in HERE documents
Message-Id: <8oij50$ogb$1@nnrp1.deja.com>

Say I have a scalar $x, which contains "abc", and I want to build the
string "abc[]". Since "$x[]" does not work - it would interpret x as an
array - I would write this as
	$x."[]"

But how can I do this, if I'm inside a HERE document? I.e.:

$r=<<!END
 ...
$x[]  <--- does not work of course
 ...
!END
;


--
Ronald Fischer <ronald_f@my-deja.com>
http://profiles.yahoo.com/ronny_fischer/


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


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

Date: Wed, 30 Aug 2000 09:23:59 GMT
From: marcel@codewerk.com (Marcel Grunauer)
Subject: Re: square brackets in HERE documents
Message-Id: <slrn8qpkjm.dqh.marcel@gandalf.local>

On Wed, 30 Aug 2000 09:12:10 GMT, Ronny <ronald_f@my-deja.com> wrote:

>Say I have a scalar $x, which contains "abc", and I want to build the
>string "abc[]". Since "$x[]" does not work - it would interpret x as an
>array - I would write this as
>	$x."[]"
>
>But how can I do this, if I'm inside a HERE document? I.e.:
>
>$r=<<!END
>...
>$x[]  <--- does not work of course
>...
>!END
>;


    $x\[]


-- 
Marcel Gr\"unauer - Codewerk plc . . . . . . . . . . . <http://www.codewerk.com>
Perl Consulting, Programming, Training, Code review . . .  <marcel@codewerk.com>
mod_perl, XML solutions - email for consultancy availability
sub AUTOLOAD{($_=$AUTOLOAD)=~s;^.*::;;;y;_; ;;print} Just_Another_Perl_Hacker();


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

Date: Tue, 29 Aug 2000 20:44:26 -0700
From: "Matthew Fox" <superior@island.net>
Subject: Trouble setting arrays and hashes in namespace $this_namespace
Message-Id: <8oi03m0417@enews4.newsguy.com>

Hello,
I need some assistance setting the values of arrays and hashes in a given
namespace. I have been trying the following:

$namespace = "NAME";
${"${namespace}::db"} = "foo";

I had hoped this would make $NAME::db contain "foo". However, $NAME::db just
ends up undefined. Does anyone have any ideas?

Also, can I just substitute a variable for a file handle? For example,

open($var,"foo.txt");

instead of

open(VAR,"foo.txt");

Or do I have to do something fancier than just the variable name? Does it
have something to do with typeglobs?

Thanks very much,
Matthew Fox

Please reply in the newsgroup. Thanks







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

Date: 30 Aug 2000 08:44:32 +0100
From: nobull@mail.com
Subject: Re: Trouble setting arrays and hashes in namespace $this_namespace
Message-Id: <u9wvgzw3lk.fsf@wcl-l.bham.ac.uk>

"Matthew Fox" <superior@island.net> writes:

> Subject: Trouble setting arrays and hashes in namespace $this_namespace

Nothing to do with arrays or hashes in your post.  Please use the
subject line to describe the content of the post.

> $namespace = "NAME";
> ${"${namespace}::db"} = "foo";
> 
> I had hoped this would make $NAME::db contain "foo".

It does.

> However, $NAME::db just ends up undefined.

I am unable to reproduce this.

> Does anyone have any ideas?

Always post a short but complete, strict[1], warning-free script that
when you run it actually produces the symptoms you describe.  I'm
guessing that your actual code is more complex and contain BEGIN
blocks and suchlike that cause statements to be executed in a
different order from the one you are expecting.
 
[1] Obviously since this is a question about symbolic refs you'd need
to have a "no strict 'refs'" in there.

> Also,

This is an unrelated question.  Please do not put two or more
unrelated questions in the same post.  Post each separately with a
relevant subject line in each case.

> can I just substitute a variable for a file handle? For example,
> 
> open($var,"foo.txt");

Yes.

> Or do I have to do something fancier than just the variable name?

The variable must contain a reference to a filehandle (or a typeglob).

$var = IO::Handle->new();

In 5.6 I seem to recall you can omit this bit as open() autovivifies
$var into an IO handle.

> Does it have something to do with typeglobs?

That's an alternative, somewhat old-fashioned way.

See: perldoc perldata/"Typeglobs and Filehandles"

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

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


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