[16159] in Perl-Users-Digest
Perl-Users Digest, Issue: 3571 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 10 17:03:12 2000
Date: Mon, 10 Jul 2000 14:02:58 -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: <963262978-v9-i3571@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 10 Jul 2000 Volume: 9 Number: 3571
Today's topics:
How to remove duplicate characters newbie@db-networks.com
Re: How to remove duplicate characters (Abigail)
Re: How to remove duplicate characters <billy@arnis-bsl.com>
Re: How to remove duplicate characters <hyagillot@tesco.net>
Re: How to remove duplicate characters <bcaligari@shipreg.com>
How to send mail with Active Perl ? <TheEx0rcist@fanclub.org>
Re: How to send mail with Active Perl ? <bwalton@rochester.rr.com>
Re: How to send mail with Active Perl ? (Abigail)
Re: How to send mail with Active Perl ? <TheEx0rcist@fanclub.org>
Re: How to send mail with Active Perl ? <TheEx0rcist@fanclub.org>
Re: how to setuid and setgid (MHM)
How to sort hash by keys, but print the elements? <sven@rheingau.netsurf.de>
Re: How to sort hash by keys, but print the elements? <news@fido.workone.com>
Re: How to sort hash by keys, but print the elements? (Keith Calvert Ivey)
Re: How to sort hash by keys, but print the elements? <aqumsieh@hyperchip.com>
Re: How to sort hash by keys, but print the elements? <thoren@southern-division.com>
Re: How to sort hash by keys, but print the elements? <sven@rheingau.netsurf.de>
Re: How to sort hash by keys, but print the elements? (Craig Berry)
how to write pid into pid file from within perl prog tony_barratt@my-deja.com
Re: how to write pid into pid file from within perl pro (Markus Fischer)
Re: how to write pid into pid file from within perl pro (Tad McClellan)
Re: how to write pid into pid file from within perl pro (Tad McClellan)
How to... <matthebraveone@yahoo.com>
Re: How to... (jason)
Re: How to... (Tad McClellan)
Re: How to... <o1technospam@skyenet.nospam.net>
Re: How to... <flavell@mail.cern.ch>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 05 Jul 2000 15:02:49 GMT
From: newbie@db-networks.com
Subject: How to remove duplicate characters
Message-Id: <9cj6ms00cebqmr33e4447f6pl6ccqffna6@4ax.com>
I am trying to remove multiple repetitions of characters.
AA ===> OK
BBB ==> OK
CCCC ==> remove
How to make it so that any repetition of any character at least 4
times gets removed?
Thanks
------------------------------
Date: 05 Jul 2000 11:49:43 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: How to remove duplicate characters
Message-Id: <slrn8m6nad.ibb.abigail@alexandra.delanet.com>
newbie@db-networks.com (newbie@db-networks.com) wrote on MMD September
MCMXCIII in <URL:news:9cj6ms00cebqmr33e4447f6pl6ccqffna6@4ax.com>:
'' I am trying to remove multiple repetitions of characters.
''
'' AA ===> OK
'' BBB ==> OK
'' CCCC ==> remove
''
'' How to make it so that any repetition of any character at least 4
'' times gets removed?
s/(.) # Any character
\1{3,} # repeated at least another 3 times.
//gsx; # Deleted, globally, include newline.
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: Wed, 05 Jul 2000 16:06:39 GMT
From: Ilja Tabachnik <billy@arnis-bsl.com>
Subject: Re: How to remove duplicate characters
Message-Id: <8jvme0$e0f$1@nnrp1.deja.com>
In article <9cj6ms00cebqmr33e4447f6pl6ccqffna6@4ax.com>,
newbie@db-networks.com wrote:
> I am trying to remove multiple repetitions of characters.
>
> AA ===> OK
> BBB ==> OK
> CCCC ==> remove
>
> How to make it so that any repetition of any character at least 4
> times gets removed?
IMHO:
$line =~ s/(.)\1{3,}//g;
Ilja.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 5 Jul 2000 21:45:38 +0100
From: "B Kemp" <hyagillot@tesco.net>
Subject: Re: How to remove duplicate characters
Message-Id: <8k0719$7im$1@barcode.tesco.net>
>'' AA ===> OK
>'' BBB ==> OK
>'' CCCC ==> remove
>''
>'' How to make it so that any repetition of any character at least 4
>'' times gets removed?
>
>
> s/(.) # Any character
> \1{3,} # repeated at least another 3 times.
> //gsx; # Deleted, globally, include newline.
Sorry, I know i should get out the manual and FRead it.
whats the \1
whats the x
PS did I mention my dyslexic tendencies?
------------------------------
Date: Thu, 6 Jul 2000 00:46:48 +0200
From: "Brendon Caligari" <bcaligari@shipreg.com>
Subject: Re: How to remove duplicate characters
Message-Id: <8k0d9g$c56$1@news.news-service.com>
<newbie@db-networks.com> wrote in message
news:9cj6ms00cebqmr33e4447f6pl6ccqffna6@4ax.com...
> I am trying to remove multiple repetitions of characters.
>
> AA ===> OK
> BBB ==> OK
> CCCC ==> remove
>
> How to make it so that any repetition of any character at least 4
> times gets removed?
>
> Thanks
This is really confusing. I'm clueless when it comes to regex and unable to
solve this problem in perl I tried to put together a script in sed.
I came up with the following, which doesn't make much sense to me as I tried
to refer to a match within the pattern itself:
s/\(.\)\1\{3,\}//g
However, sed did not complain, and while i guess such a regex is really
inefficient it seemed to work.
Then i used s2p that comes with the perl distribution to convert the sed
script to perl and got the following perl substitution:
s/(.)1{3,}//g;
however, this does not work and the 1 has to be escaped to s/(.)\1{3,}//g;
doh..please help!!!! am i on the right track?
Brendon
+++++
------------------------------
Date: Wed, 5 Jul 2000 00:54:41 +0200
From: "TheEx0rcist" <TheEx0rcist@fanclub.org>
Subject: How to send mail with Active Perl ?
Message-Id: <8jtpun$jgi$1@news3.isdnet.net>
Under Linux, I was just doing a ' open MAIL "|sendmail -t" ' to send mail
but now I am under Win2k and am trying to send mail. How do I do? Is there a
module that ships with Active Perl 5.6.0 to do this?
Net::SMTP doesn't ship with it and the link is broken on CPAN.
Please help !!
--
TheEx0rcist
------------------------------
Date: Tue, 04 Jul 2000 23:14:58 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: How to send mail with Active Perl ?
Message-Id: <39627039.47927DA9@rochester.rr.com>
TheEx0rcist wrote:
>
> Under Linux, I was just doing a ' open MAIL "|sendmail -t" ' to send mail
> but now I am under Win2k and am trying to send mail. How do I do? Is there a
> module that ships with Active Perl 5.6.0 to do this?
>
> Net::SMTP doesn't ship with it and the link is broken on CPAN.
>
> Please help !!
>
> --
> TheEx0rcist
Try:
ppm install libnet
--
Bob Walton
------------------------------
Date: 04 Jul 2000 19:54:53 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: How to send mail with Active Perl ?
Message-Id: <slrn8m4vc2.59a.abigail@alexandra.delanet.com>
TheEx0rcist (TheEx0rcist@fanclub.org) wrote on MMCDXCIX September
MCMXCIII in <URL:news:8jtpun$jgi$1@news3.isdnet.net>:
.. Under Linux, I was just doing a ' open MAIL "|sendmail -t" ' to send mail
.. but now I am under Win2k and am trying to send mail. How do I do? Is there a
.. module that ships with Active Perl 5.6.0 to do this?
That isn't a Perl question. It all depends on your local setup.
Abigail
--
sub A::TIESCALAR{bless\my$x=>'A'};package B;@q=qw/Hacker Perl
Another Just/;use overload'""',sub{pop @q};sub A::FETCH{bless
\my $y=>B};tie my$shoe=>'A';print"$shoe $shoe $shoe $shoe\n";
------------------------------
Date: Wed, 5 Jul 2000 02:06:37 +0200
From: "TheEx0rcist" <TheEx0rcist@fanclub.org>
Subject: Re: How to send mail with Active Perl ?
Message-Id: <8jtu5k$2g9p$1@news4.isdnet.net>
> ppm install libnet
THANK YOU BOB !!!
------------------------------
Date: Wed, 5 Jul 2000 02:06:59 +0200
From: "TheEx0rcist" <TheEx0rcist@fanclub.org>
Subject: Re: How to send mail with Active Perl ?
Message-Id: <8jtu6b$2g9v$1@news4.isdnet.net>
> That isn't a Perl question. It all depends on your local setup.
huh???
------------------------------
Date: Sun, 09 Jul 2000 22:44:13 GMT
From: mail-abuse@uu.net (MHM)
Subject: Re: how to setuid and setgid
Message-Id: <1f7a5.2576$bR6.218673@bgtnsc04-news.ops.worldnet.att.net>
In article <3948ECEE.EE6A5ED@attglobal.net>, Drew Simonis <care227@attglobal.net> wrote:
>Dominic Prakash wrote:
>>
>> How do I do that? Presently I am using an external C application with (-
>> r-sr-sr-x 1 admin) permissions. This C application just uses setuid
>> and setgid functions. How do I do that in Perl?
>>
>
>
>Learn thy operating system.
>
>$ man chmod
>
>This has nothing to do with Perl.
Interesting response.
Villy, with his "Check perlvar for the variables $< and $>...." is much more
condusive to an exchange of thoughts and ideas. I have been digging around
the man pages and CPAN for almost two days and suspected that this was the
most appropriate way to solve the problem (yes, I too need to monkey around
with permissions). I'm just glad that someone out there has the intestinal
fortitude to give a decent answer, rather than attempting to belittle any one
with a question.
PS: If you are trying to do it in Perl, then it has a lot to do with Perl. I
for one would like to minimize the number of operating system calls that my
script uses.
Thank you Villy and Dominic.
------------------------------
Date: Tue, 04 Jul 2000 15:32:18 GMT
From: Sven Rudolph <sven@rheingau.netsurf.de>
Subject: How to sort hash by keys, but print the elements?
Message-Id: <8jt023$hp0$1@nnrp1.deja.com>
Hello
I'm new to perl programming and don't know how to solve the following
problem.
I have two textfiles with line separated strings. The files are
identical but the first file has all strings in lowercase and the
second
file has strings with lower and uppercase mixed.
First I'm reading the two files into two arrays @stringlower and
@string.
Then I'm creating a hash .
for($i=0;$i<@string;$i++)
{
$stringhash{$stringlower[$i]} = "$string[$i]";
}
Now I want to create an array that contains the elements of
%stringhash
but sorted by the keys of %stringhash.
I tried this:
@list = sort keys %stringhash;
But this results in @list containing %stringhash's sorted keys.
But I need @list to contain %stringhash's elements sorted by
%stringhash's keys.
I'm sure this can be done very easily, but I don't know how.
Another (easiyer) solution would be sorting @string but
caseinsensitive,
but I don't know how to tell sort() how to do this.
Can anybody help me?
Thanks in advance
Sven Rudolph
P.S. Broken english spoken perfectely ;-)
--
--
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 4 Jul 2000 17:50:23 +0200
From: Kirill Miazine <news@fido.workone.com>
Subject: Re: How to sort hash by keys, but print the elements?
Message-Id: <Pine.LNX.4.21.0007041744270.26627-100000@isolde.uio.no>
sort { lc($a) cmp lc($b) } @string;
# Another (easiyer) solution would be sorting @string but
# caseinsensitive,
# but I don't know how to tell sort() how to do this.
#
# Can anybody help me?
------------------------------
Date: Tue, 04 Jul 2000 15:54:56 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: How to sort hash by keys, but print the elements?
Message-Id: <396406d8.57231482@nntp.idsonline.com>
Sven Rudolph <sven@rheingau.netsurf.de> wrote:
> for($i=0;$i<@string;$i++)
> {
> $stringhash{$stringlower[$i]} = "$string[$i]";
> }
Why do you have quotes there? Anyway, a more Perlish way to do
that whole loop would be
@stringhash{@stringlower} = @string;
> Now I want to create an array that contains the elements of
>%stringhash
> but sorted by the keys of %stringhash.
>
> I tried this:
> @list = sort keys %stringhash;
@list = map { $stringhash{$_} } sort keys %stringhash;
> Another (easiyer) solution would be sorting @string but
>caseinsensitive,
> but I don't know how to tell sort() how to do this.
@string = sort { lc $a cmp lc $b } @string;
If you have really large files, it might be worth additional
coding (the Schwartzian transform or the Guttman-Rosler
transform -- search Deja.com) to avoid recomputing the
lowercased strings during the sort.
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
------------------------------
Date: Tue, 04 Jul 2000 16:00:33 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: How to sort hash by keys, but print the elements?
Message-Id: <7a7lb1anrx.fsf@merlin.hyperchip.com>
Sven Rudolph <sven@rheingau.netsurf.de> writes:
> I have two textfiles with line separated strings. The files are
> identical but the first file has all strings in lowercase and the
> second
> file has strings with lower and uppercase mixed.
>
> First I'm reading the two files into two arrays @stringlower and
> @string.
>
> Then I'm creating a hash .
>
> for($i=0;$i<@string;$i++)
> {
> $stringhash{$stringlower[$i]} = "$string[$i]";
You don't need to quote the right hand side.
> }
The above can be done in one step:
@stringhash{@stringlower} = @string;
This is called a 'hash slice'. Cute, eh?
> Now I want to create an array that contains the elements of
> %stringhash
> but sorted by the keys of %stringhash.
>
> I tried this:
> @list = sort keys %stringhash;
>
> But this results in @list containing %stringhash's sorted keys.
> But I need @list to contain %stringhash's elements sorted by
> %stringhash's keys.
By 'elements', I'll assume you mean 'values'. Then, you want:
@list = map {$stringhash{$_}} sort keys %stringhash;
This basically sorts the keys of %stringhash, and then uses those keys
to get the corresponding values back, using map().
Checkout map() in perlfunc.
--Ala
------------------------------
Date: Tue, 4 Jul 2000 18:14:15 +0200
From: "Thoren Johne" <thoren@southern-division.com>
Subject: Re: How to sort hash by keys, but print the elements?
Message-Id: <8jt2ij$n2t$10$1@news.t-online.com>
Sven Rudolph <sven@rheingau.netsurf.de> wrote in message
news:8jt023$hp0$1@nnrp1.deja.com...
> Another (easiyer) solution would be sorting @string but
> caseinsensitive, but I don't know how to tell sort() how
> to do this.
if i'd understand your question, i think you like to read
perlfaq4 - How do I sort an array by (anything)?
and
perlfunc - for the function 'lc'
then, you could use:
@string = sort { lc $a cmp lc $b } @string;
gruß
thoren
8#X
--
----------------------------------------------------------------------
Thoren Johne - 8#X - thoren@southern-division.com
Southern Division Classic Bikes - www.southern-division.com
------------------------------
Date: Wed, 05 Jul 2000 03:56:14 GMT
From: Sven Rudolph <sven@rheingau.netsurf.de>
Subject: Re: How to sort hash by keys, but print the elements?
Message-Id: <8jubkq$f68$1@nnrp1.deja.com>
Hello Thoren
> ...i think you like to read
> perlfaq4...
Where can I find this? Is there a list of suggested readings?
I'm currently reading O'Reilly'S "Learning Perl" and "Perl", but I think
this shouldn't be the only way to learn Perl.
Oh, well. And I just found out, that I have a perldoc command on my
Linuxbox :-\ (better late than never)
> ...perlfunc - for the function 'lc'
Argh! I tried it with 'lowercase'. (close, but still missing)
> @string = sort { lc $a cmp lc $b } @string;
Thanks a lot. This works just fine :-)
Regards
Sven
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 05 Jul 2000 22:59:13 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: How to sort hash by keys, but print the elements?
Message-Id: <sm7fe1rcgas117@corp.supernews.com>
Sven Rudolph (sven@rheingau.netsurf.de) wrote:
: I have two textfiles with line separated strings. The files are
: identical but the first file has all strings in lowercase and the
: second file has strings with lower and uppercase mixed.
:
: First I'm reading the two files into two arrays @stringlower and
: @string.
:
: Then I'm creating a hash .
:
: for($i=0;$i<@string;$i++)
: {
: $stringhash{$stringlower[$i]} = "$string[$i]";
: }
First, those double quotes on the right are redundant. Second, you can
write that more compactly and efficiently as:
@stringhash{@stringlower} = @string;
This is called a hash slice, and it's a very useful trick to learn.
(I'd suggest an error check to be sure the two arrays are actually the
same length before you start such processing, by the way.)
: Now I want to create an array that contains the elements of
: %stringhash but sorted by the keys of %stringhash.
@list = @stringhash{sort keys %stringhash};
(Another hash slice.)
: Another (easiyer) solution would be sorting @string but
: caseinsensitive, but I don't know how to tell sort() how to do this.
Just write your own comparison block, and normalize the case:
@foo = sort { lc $a cmp lc $b } @bar;
Note that this will result in QUUX and qUuX appearing in unpredictable
order in the result array. If you want to sort case-insensitively but
then fall back on case to sort otherwise equal strings, you can do:
@foo = sort { lc $a cmp lc $b or $a cmp $b } @bar;
--
| Craig Berry - http://www.cinenet.net/users/cberry/home.html
--*-- "Beauty and strength, leaping laughter and delicious
| languor, force and fire, are of us." - Liber AL II:20
------------------------------
Date: Wed, 05 Jul 2000 17:10:36 GMT
From: tony_barratt@my-deja.com
Subject: how to write pid into pid file from within perl prog
Message-Id: <8jvq60$gu4$1@nnrp1.deja.com>
I want to invoke a perl program, 'fred' say, from the command line and
perlprog fred needs to write it's own pid into /var/run/fred.pid.
But i'm not clear on how to do this, something better than a
system(" echo $$ > /var/run/$0.pid");
Which doesn't work but it's a nice idea :-)
So I can later whack fred's process with a kill -USR1 `cat
/var/run/fred.pid` sorta thing.
<reading the fine manual would be fine, but which manual>
TIA
Tony
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 5 Jul 2000 17:38:57 GMT
From: mfischer-news@josefine.ben.tuwien.ac.at (Markus Fischer)
Subject: Re: how to write pid into pid file from within perl prog
Message-Id: <slrn8m6slh.h5c.mfischer-news@josefine.ben.tuwien.ac.at>
In article <8jvq60$gu4$1@nnrp1.deja.com>,
tony_barratt@my-deja.com <tony_barratt@my-deja.com> wrote:
>system(" echo $$ > /var/run/$0.pid");
>Which doesn't work but it's a nice idea :-)
open F, ">/var/run/$0.pid";
print F $$
close F;
I mean .. I don't know why this should me less dirty / more clean
than yours :)
I'm no guru but I would to it that why. Maybe thats awful and
wrong too :/
kind regards,
Maruks
--
Markus Fischer, http://josefine.ben.tuwien.ac.at/~mfischer/
EMail: mfischer@josefine.ben.tuwien.ac.at
PGP Public Key: http://josefine.ben.tuwien.ac.at/~mfischer/C2272BD0.asc
PGP Fingerprint: D3B0 DD4F E12B F911 3CE1 C2B5 D674 B445 C227 2BD0
- Free Software For A Free World -
------------------------------
Date: Wed, 5 Jul 2000 12:55:25 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: how to write pid into pid file from within perl prog
Message-Id: <slrn8m6q3t.hj8.tadmc@magna.metronet.com>
On Wed, 05 Jul 2000 17:10:36 GMT, tony_barratt@my-deja.com <tony_barratt@my-deja.com> wrote:
>I want to invoke a perl program, 'fred' say, from the command line and
>perlprog fred needs to write it's own pid into /var/run/fred.pid.
>But i'm not clear on how to do this, something better than a
>system(" echo $$ > /var/run/$0.pid");
>Which doesn't work but it's a nice idea :-)
^^^^^^^^^^^^
^^^^^^^^^^^^
What does that mean when you say it?
It looks OK to me (though you should just do it in native Perl, as below).
>So I can later whack fred's process with a kill -USR1 `cat
>/var/run/fred.pid` sorta thing.
>
><reading the fine manual would be fine, but which manual>
perldoc -f open # instead of shell redirection
perldoc -f print # instead of echo
perldoc perlvar # Perl also has the PID in a var named $$
open(PID, "> /var/run/$0.pid") || die "could not open '/var/run/$0.pid' $!";
print PID "$$\n";
close(PID);
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 5 Jul 2000 13:14:16 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: how to write pid into pid file from within perl prog
Message-Id: <slrn8m6r78.hmi.tadmc@magna.metronet.com>
On 5 Jul 2000 17:38:57 GMT, Markus Fischer <mfischer-news@josefine.ben.tuwien.ac.at> wrote:
> open F, ">/var/run/$0.pid";
>I'm no guru but I would to it that why. Maybe thats awful and
>wrong too :/
I'm afraid that not checking the return value from open() is
indeed awful.
Don't do that.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 05 Jul 2000 11:03:11 +0200
From: Mat <matthebraveone@yahoo.com>
Subject: How to...
Message-Id: <3962F9CF.3EC0A996@yahoo.com>
Hello,
I didn't know how to name this problem...
I've got two files, one of them has to be modified, the second one works
as a configuration file based on the modification will be done.
The configuration file contains names of fields which are used as
variables in the program, e.g.:
op_name;op_adr_1;op_adr_2
Program has coresponding variables: $op_name, $op_adr_1, $op_adr_2,
depending on definition in configuration file. The sequence of field
names can vary.
Based on it should be the names and sequence of variables in the
program, e.g.:
$config[0] = op_name => $op_name = $in_file[0]
$config[2] = op_adr_1 => $op_adr_1 = $in_file[2]
$config[3] = op_adr_1 => $op_adr_1 = $in_file[3]
In other words what I intend to do is to modify names and sequence of
variables in the main program depending on configuration name.
I will be very grateful for any help,
kind regards,
Maciek
------------------------------
Date: Wed, 05 Jul 2000 11:45:02 GMT
From: elephant@squirrelgroup.com (jason)
Subject: Re: How to...
Message-Id: <MPG.13cdbcf3f89abfa4989769@news>
Mat writes ..
>I didn't know how to name this problem...
>
>I've got two files, one of them has to be modified, the second one works
>as a configuration file based on the modification will be done.
>The configuration file contains names of fields which are used as
>variables in the program, e.g.:
>
>op_name;op_adr_1;op_adr_2
>
>Program has coresponding variables: $op_name, $op_adr_1, $op_adr_2,
>depending on definition in configuration file. The sequence of field
>names can vary.
>Based on it should be the names and sequence of variables in the
>program, e.g.:
>
>$config[0] = op_name => $op_name = $in_file[0]
>$config[2] = op_adr_1 => $op_adr_1 = $in_file[2]
>$config[3] = op_adr_1 => $op_adr_1 = $in_file[3]
>
>
>In other words what I intend to do is to modify names and sequence of
>variables in the main program depending on configuration name.
>
>I will be very grateful for any help,
use a hash .. the code would look something like the following
#!/usr/bin/perl -w
use strict;
my %hash = ();
open INFILE, 'infile' or die "Bad open: $!";
# the next line assumes one value per line in your infile this may
# need to be changed depending on the structure of that file
my @infile = <INFILE>;
close INFILE;
# the following line assumes that there might be multiple lines of
# variable names .. if there's only one then only one <> needs to be
# done
while(<DATA>)
{
chomp( my @varNames = split ';');
@hash{ @varNames } = @infile;
}
__DATA__
op_name;op_adr_1;op_adr_2
--
jason - elephant@squirrelgroup.com -
------------------------------
Date: Wed, 5 Jul 2000 09:00:44 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: How to...
Message-Id: <slrn8m6cbs.ghk.tadmc@magna.metronet.com>
On Wed, 05 Jul 2000 11:03:11 +0200, Mat <matthebraveone@yahoo.com> wrote:
>I didn't know how to name this problem...
But as a consequence, your post may well be ignored by many folks.
You really must do better, even when it is hard, or you will
limit the readership for your posting.
Subject: File modification
even that would likely have avoided some ignoration.
Or, better yet:
Subject: Program/script file modification
>I've got two files, one of them has to be modified, the second one works
>as a configuration file based on the modification will be done.
And the "first file" is Perl source code, right?
>The configuration file contains names of fields which are used as
>variables in the program, e.g.:
>
>op_name;op_adr_1;op_adr_2
>
>Program has coresponding variables: $op_name, $op_adr_1, $op_adr_2,
Oh. I see what you want to do now.
Subject: I want to use Evil Symbolic References
might have been accurate.
(I'm joking. You didn't know you wanted "Symbolic references",
but I can see that you are heading there.
Don't go!
)
To see why they are evil:
http://www.plover.com/~mjd/perl/varvarname.html
http://www.plover.com/~mjd/perl/varvarname2.html
http://www.plover.com/~mjd/perl/varvarname3.html
>depending on definition in configuration file. The sequence of field
>names can vary.
>Based on it should be the names and sequence of variables in the
>program, e.g.:
>
>$config[0] = op_name => $op_name = $in_file[0]
>$config[2] = op_adr_1 => $op_adr_1 = $in_file[2]
>$config[3] = op_adr_1 => $op_adr_1 = $in_file[3]
Use a hash instead of scalars in the program file:
$config[0] = op_name => $hash{op_name} = $in_file[0]
or
$config[0] = op_name => $hash{$config[0]} = $in_file[0]
>In other words what I intend to do is to modify names and sequence of
>variables in the main program depending on configuration name.
Since you are processing code as data, the code will be
a string:
Perl FAQ, part 4:
"How can I expand variables in text strings?"
Which also mentions using a hash instead.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 7 Jul 2000 00:30:59 -0500
From: "Jim Kauzlarich" <o1technospam@skyenet.nospam.net>
Subject: Re: How to...
Message-Id: <CPd95.5861$%J6.12301@newsfeed.slurp.net>
"Tad McClellan" <tadmc@metronet.com> wrote in message
news:slrn8m6cbs.ghk.tadmc@magna.metronet.com...
<snip>
> Subject: I want to use Evil Symbolic References
<snip>
> To see why they are evil:
>
> http://www.plover.com/~mjd/perl/varvarname.html
> http://www.plover.com/~mjd/perl/varvarname2.html
> http://www.plover.com/~mjd/perl/varvarname3.html
Great articles! Thanks for pointing them out Tad. Very illuminating. They
also bring to the fore what was bouncing about in the back of my head when I
in my Re: to a Re: to my latest newbie question.
Of course this brings more questions bubbling forth... but as they concern
self-modifying code, I'm gonna wait until I am much more versed in Perl.
(At the very least)
JMK
------------------------------
Date: Fri, 7 Jul 2000 12:32:12 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: How to...
Message-Id: <Pine.GHP.4.21.0007071222370.8422-100000@hpplus03.cern.ch>
On Fri, 7 Jul 2000, Jim Kauzlarich wrote:
> > http://www.plover.com/~mjd/perl/varvarname.html
[...]
> Great articles! Thanks for pointing them out Tad. Very illuminating.
Indeed. I received an abusively worded email from one lurker (well,
its usenet posting history seems to comprise a grand total of eight
postings, to mailing.database.* groups whatever they might be),
demanding to know what was my "excuse" for recommending these pages
in a recent thread.
I don't propose to reply to the email, but I think I can state here
publicly that no excuse seems to be needed. The advice is good, and
well-argued.
However, if any further email abuse is received, I reserve the right
to take appropriate action.
cheers
------------------------------
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 3571
**************************************