[15737] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3150 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 24 18:05:58 2000

Date: Wed, 24 May 2000 15:05:28 -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: <959205928-v9-i3150@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 24 May 2000     Volume: 9 Number: 3150

Today's topics:
    Re: @lets = split(/\_/, $value); ? (Bart Lateur)
        [ANNOUNCE] Language::Basic karger@fermi2.chem.yale.edu
        [Beginner Q] reading multiline records from a file? <richard.crane@yale.edu>
    Re: [Beginner Q] reading multiline records from a file? <rootbeer@redcat.com>
    Re: [LWP] Requesting from the clients' IP, not the serv (John Stanley)
    Re: [LWP] Requesting from the clients' IP, not the serv <charles.henry@engineer2k.com>
    Re: Accounting Systems Written In Perl??? <red_orc@my-deja.com>
        Active Perl installation prblem - Could not locate a PP <trentoc@bellatlantic.net>
        Announce: MIME-tools 5.115 uploaded to CPAN <eryq@zeegee.com>
    Re: Array Question <lr@hpl.hp.com>
    Re: Array Question (Jerome O'Neil)
    Re: Array Question <lr@hpl.hp.com>
        C-Kermit script as Perl sub <MSH@question.com>
    Re: C-Kermit script as Perl sub <rootbeer@redcat.com>
    Re: C-Kermit script as Perl sub <MSH@question.com>
    Re: C-Kermit script as Perl sub <Petri_member@newsguy.com>
    Re: Can't Knit Two Files Together <rootbeer@redcat.com>
    Re: Can't Knit Two Files Together <red_orc@my-deja.com>
    Re: Can't Knit Two Files Together <godzilla@stomp.stomp.tokyo>
    Re: Can't Knit Two Files Together <godzilla@stomp.stomp.tokyo>
    Re: Can't Knit Two Files Together <lr@hpl.hp.com>
    Re: Can't Knit Two Files Together <lr@hpl.hp.com>
    Re: Can't Knit Two Files Together <lr@hpl.hp.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 24 May 2000 19:56:39 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: @lets = split(/\_/, $value); ?
Message-Id: <392c2e47.364152@news.skynet.be>

Moltimer wrote:

>I split a value by "_"
>The odinary value should have only two of "_" like "A_B_C".
>
>If there are many "_"s in middle world like "A_B-1_B-2_B-3_C,
>How can I get value like "A", "B-1_B-2_B-3" and "C" instead of "A", "B-1"
>and "B-2" ?

Is the fact that all parts in the middle start with the same letter,
typical?

	$_ = 'A_B-1_B-2_B-3_C-1_C-2_D';
	my @let;
	while(/(([A-Z])(?:-\d+(?:_\2-\d+)*)?)/g) {
	    push @let, $1;
	}
	$, = ';'; $\ = "\n";
	print @let;
-->
	A;B-1_B-2_B-3;C-1_C-2;D

-- 
	Bart.


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

Date: 24 May 2000 19:46:33 GMT
From: karger@fermi2.chem.yale.edu
Subject: [ANNOUNCE] Language::Basic
Message-Id: <RsWW4.51243$g41.2157996@news-west.usenetserver.com>

[edited slightly by CLPA moderator merlyn@stonehenge.com]

You long for the simple GOTO; you have nostalgiac memories of your 6502,
8086, TRS-80; the words "I SMELL A WUMPUS!" elicit chilling fear and crafty
excitement... and you've unknowingly been waiting all these years for
Language::Basic.

Language::Basic is a module with methods for parsing and implementing the
BASIC computer language. The module comes with a short Perl script that
will run BASIC programs. And if you act now, you can also receive --- FREE!
--- Gregory Yob's classic adventure game, Hunt the Wumpus.

No, we're not talking about modern versions of BASIC, with variable
declaration, multi-line IF/THENs, and GUI interfaces. Bah! This is
microcomputer BASIC, from the days when men were men, women were women, and
subroutines were GOSUB/RETURN; when a terminal was 24x80 (or 40) and
black and white (or green, or orange); when every line had a line number,
and POKE was a mystical word of power.

So don't delay! Act now and pick up your copy of the very best (pre-Perl)
interpreted language.

Operators (or servers, anyway) are standing by at
http://www.cpan.org/modules/by-authors/id/A/AK/AKARGER/

-Amir Karger
karger@fermi2.chem.yale.edu





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

Date: Wed, 24 May 2000 16:44:15 -0400
From: Richard Crane <richard.crane@yale.edu>
Subject: [Beginner Q] reading multiline records from a file?
Message-Id: <392C3F1F.223101@yale.edu>

This is a multi-part message in MIME format.
--------------9912427EF8CBCA322B4B7E7E
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Got
while (<>) { if (cond) {do_something} } working.
Now the do_something needs to read some more  lines from the file --
can't come up with a construct that will do
that.
Sample file lines
----
A 10
A  21
B 4
B 29
B 3
--
Need to iterate over the A's,  B's, etc.

Suggestions?

TIA

--------------9912427EF8CBCA322B4B7E7E
Content-Type: text/x-vcard; charset=us-ascii;
 name="richard.crane.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Richard Crane
Content-Disposition: attachment;
 filename="richard.crane.vcf"

begin:vcard 
n:Crane;Richard
tel;fax:(203) 432-0593
tel;work:(203) 432-1256
x-mozilla-html:FALSE
org:Yale University;Workstation Support Services
version:2.1
email;internet:richard.crane@yale.edu
title:Staff Specialist
adr;quoted-printable:;;Arthur K.Watson Hall, Room 015=0D=0A51 Prospect Street;New Haven ;CT;06520;USA
fn:Richard Crane
end:vcard

--------------9912427EF8CBCA322B4B7E7E--



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

Date: Wed, 24 May 2000 14:27:35 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: [Beginner Q] reading multiline records from a file?
Message-Id: <Pine.GSO.4.10.10005241425030.14618-100000@user2.teleport.com>

On Wed, 24 May 2000, Richard Crane wrote:

> Got while (<>) { if (cond) {do_something} } working.

> Now the do_something needs to read some more  lines from the file --

Unless you know in advance how many lines to read, this gets tough. Maybe,
if the file is small enough, you want to read the whole thing into memory,
gathering together each chunk of stuff that you want to pass to your other
code. 

If you must do it as you say, you'll probably need to use seek() and
tell() so that you can back up when you realize that you've read too many
lines in the inner loop, and let the outer loop have one. There are other
ways to do this, of course.

Not a beginner question, after all!

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 24 May 2000 18:13:58 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: [LWP] Requesting from the clients' IP, not the server's
Message-Id: <8gh656$r0v$1@news.NERO.NET>

In article <8ggur4$4lj$1@news2.isdnet.net>,
Charles Henry <charles.henry@engineer2k.com> wrote:
>There is a script "geturl.pl" that is located on my server. It just does an
>HTTP request. But the problem is that whenever it is accessed, remotely or
>not, it ALWAYS uses the SERVER's IP, not the CLIENT's. 

No, it always uses the client's IP. It's just that geturl.pl is the
client. 

>I am not trying to
>spoof, I just want the script to use the client's IP when making requests,

And how do you propose that the data that geturl.pl is asking for be
returned to geturl.pl if you pretend to be coming from a different IP
address than where geturl.pl is running from? The packets will be
returned to a system that is not looking for them and does not have a
connection open to receive them. Pretty useless, other than for DOS
attacks.



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

Date: Wed, 24 May 2000 21:14:39 +0200
From: "Charles Henry" <charles.henry@engineer2k.com>
Subject: Re: [LWP] Requesting from the clients' IP, not the server's
Message-Id: <8gh9ni$1stg$1@news4.isdnet.net>

> >There is a script "geturl.pl" that is located on my server. It just does
an
> >HTTP request. But the problem is that whenever it is accessed, remotely
or
> >not, it ALWAYS uses the SERVER's IP, not the CLIENT's.
>
> No, it always uses the client's IP. It's just that geturl.pl is the
> client.
>
> >I am not trying to
> >spoof, I just want the script to use the client's IP when making
requests,
>
> And how do you propose that the data that geturl.pl is asking for be
> returned to geturl.pl if you pretend to be coming from a different IP
> address than where geturl.pl is running from? The packets will be
> returned to a system that is not looking for them and does not have a
> connection open to receive them. Pretty useless, other than for DOS
> attacks.

Thanks for your reply (that didn't help at all, sorry).

If geturl.pl was :
#-- geturl.pl
print "Location: http://www.url.com\n\n";
#-- _END_

It would've used the IP of the person who accessed the script, even though
"geturl.pl is the client" (like you say) thus has the ip of the server it is
run from.

Unfortunately, that method doesn't allow as many customisations as with the
great LWP UserAgent. I mean you can't say (as far as I know) :
print "Location: http://www.url.com\nReferer: http://www.home.com\n\n";

Please correct me if I'm wrong ...

--
Charles Henry




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

Date: Wed, 24 May 2000 18:25:31 GMT
From: Rodney Engdahl <red_orc@my-deja.com>
Subject: Re: Accounting Systems Written In Perl???
Message-Id: <8gh6q7$nh2$1@nnrp1.deja.com>

In article <392aef62.2826917312@news.wildapache.net>,
  otrcomm**NO_SPAM**@wildapache.net wrote:
> Hello,
>
> Does anyone know if there are any decent accounting systems written in
perl
> that will run on a Linux system?
>
> Thanks,
> Murrah Boswell
>

You might have tried using any of the standard search engines on the
web, looking for accounting systems and perl:

http://search.excite.com/search.gw?search=%2B%22accounting+system%22+%2B%22perl%22&tsug=-1&csug=7&lang=en

NB: WebAccountant Development Page
--------

Some drink at the fountain of knowledge...others just gargle.


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


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

Date: Wed, 24 May 2000 20:38:01 GMT
From: "Trento Castricone" <trentoc@bellatlantic.net>
Subject: Active Perl installation prblem - Could not locate a PPD file for PPM
Message-Id: <J4XW4.2514$Ym2.47482@typhoon2.ba-dsg.net>

The installation of Active Perl 5.6 went smoothly.
When I tried to install the PPM update as directed, I get the following
messages.

This is a virgin install.
Any help would be appreciated.

C:\>perl -v
This is perl, v5.6.0 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)

C:\>ppmfix.bat
C:\>ppm verify --upgrade --location=. PPM
Error verifying PPM: Could not locate a PPD file for PPM

Thanks
trento castricone




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

Date: Wed, 24 May 2000 11:14:40 -0400
From: Eryq <eryq@zeegee.com>
Subject: Announce: MIME-tools 5.115 uploaded to CPAN
Message-Id: <7tWW4.51246$g41.2155342@news-west.usenetserver.com>

Ok, 5.x is ready for prime-time.  Here's the scoop:

* Major speed and structural improvements to the parser. 
* Better, faster storage of in-core data.
* Convenient new one-directory-per-message parsing mechanism added. 
* Elimination of $', $` and $&. Wow... I still can't believe I missed
this. D'OH!
* Parser is more tolerant of weird EOL termination, and "From " lines in
headers. 
* Parser now catches syntax errors in headers
* Better integration with Mail::Internet (e.g., smtpsend should now
work)
* Miscellaneous cleanup of warnings, etc.

Bleeding-edge code available from:

	http://www.zeegee.com/code/perl/MIME-tools

On-line-documentation:

	http://www.zeegee.com/code/perl/MIME-tools/docs

Enjoy.  Holler if it breaks.


Eryq






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

Date: Wed, 24 May 2000 11:22:08 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Array Question
Message-Id: <MPG.1395bda8e4f1d0ed98aacb@nntp.hpl.hp.com>

In article <40UW4.6438$QB4.476558@news.uswest.net> on Wed, 24 May 2000 
17:08:16 GMT, Jerome O'Neil <jerome@activeindexing.com> says...

 ...

> On initialization, just add a comma:
> 
> %pers_record=(
>    'Bogdan'=>{'Address'=>'C1605','Phone'=>'x7869','College'=>'BMC'},
>    'Jones' =>{'Address'=>'12345','Phone'=>'x8367','College'=>'GRCC'}
>    );

A small but, I think, important point:

The final line, 'Jones' ..., should end with a comma just as the first 
line does.  Then the line doesn't have to be changed when it is 
inevitably no longer the final line.

This innocuous trailing comma is yet another feature adopted from C, and 
should be an habitual part of any list initialization.

> Its worth noting that if you use fat commas (=>) the single
> quotes arround your keys is redundant.
> 
> %foo = ( unquoted_key => 'quoted_value');
> 
> So you can reduce your handicap by several strokes.
> 
> If you want to add a record to an existing hash, you would
> do it the same way you normaly would.
> 
> $pers_record{'Jones'} = {Address => '12345', Phone => 'x8367'};
               ^     ^

Those quotes are superfluous also, for the same reason.

You failed to note that any automatic quoting requires that the hash key 
be parsable as a Perl identifier (leading letter or underscore, all 
other characters letters, underscores or digits).  (Numerical keys 
needn't be quoted, in any case.)

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


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

Date: Wed, 24 May 2000 18:29:17 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: Array Question
Message-Id: <1cVW4.6469$QB4.481218@news.uswest.net>

Larry Rosler <lr@hpl.hp.com> elucidates:
> In article <40UW4.6438$QB4.476558@news.uswest.net> on Wed, 24 May 2000 
> 17:08:16 GMT, Jerome O'Neil <jerome@activeindexing.com> says...
> 
> ...
> 
>> On initialization, just add a comma:
>> 
>> %pers_record=(
>>    'Bogdan'=>{'Address'=>'C1605','Phone'=>'x7869','College'=>'BMC'},
>>    'Jones' =>{'Address'=>'12345','Phone'=>'x8367','College'=>'GRCC'}
>>    );
> 
> A small but, I think, important point:
> 
> The final line, 'Jones' ..., should end with a comma just as the first 
> line does.  Then the line doesn't have to be changed when it is 
> inevitably no longer the final line.

Indeed.  I was just explaining this to a co-worker of mine yesterday.

I don't know why I didn't explain it now.  Too much to type!

> You failed to note that any automatic quoting requires that the hash key 
> be parsable as a Perl identifier (leading letter or underscore, all 
> other characters letters, underscores or digits).  (Numerical keys 
> needn't be quoted, in any case.)

Is this in all cases, or just when you are using an unquoted key? 


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

Date: Wed, 24 May 2000 12:46:44 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Array Question
Message-Id: <MPG.1395d18279c9b6b598aad0@nntp.hpl.hp.com>

In article <1cVW4.6469$QB4.481218@news.uswest.net> on Wed, 24 May 2000 
18:29:17 GMT, Jerome O'Neil <jerome@activeindexing.com> says...
> Larry Rosler <lr@hpl.hp.com> elucidates:
> > In article <40UW4.6438$QB4.476558@news.uswest.net> on Wed, 24 May 2000 
> > 17:08:16 GMT, Jerome O'Neil <jerome@activeindexing.com> says...
> > 
> > ...
> > 
> >> On initialization, just add a comma:
> >> 
> >> %pers_record=(
> >>    'Bogdan'=>{'Address'=>'C1605','Phone'=>'x7869','College'=>'BMC'},
> >>    'Jones' =>{'Address'=>'12345','Phone'=>'x8367','College'=>'GRCC'}
> >>    );
> > 
> > A small but, I think, important point:
> > 
> > The final line, 'Jones' ..., should end with a comma just as the first 
> > line does.  Then the line doesn't have to be changed when it is 
> > inevitably no longer the final line.
> 
> Indeed.  I was just explaining this to a co-worker of mine yesterday.
> 
> I don't know why I didn't explain it now.  Too much to type!

Just one little comma would have done it.  No explanation needed.  :-)

> > You failed to note that any automatic quoting requires that the hash key 
> > be parsable as a Perl identifier (leading letter or underscore, all 
> > other characters letters, underscores or digits).  (Numerical keys 
> > needn't be quoted, in any case.)
> 
> Is this in all cases, or just when you are using an unquoted key? 

I'm not sure I understand the question, so I'll just answer with 
generalities.

Any string can be used as a hash key.  In the hash-index context or on 
the left side of a =>, a string (bareword) that looks like an identifier 
will be auto-quoted.

A number need not be quoted, because it will be converted into a string 
if used as a hash key.  However, note that these have different keys, as 
someone found out the hard way according to a recent post here:

    $h{01}

    $h{'01'}

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


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

Date: Wed, 24 May 2000 15:37:10 -0400
From: MSH <MSH@question.com>
Subject: C-Kermit script as Perl sub
Message-Id: <392C2F66.FB1F0F20@question.com>

Hi,
        I need to automate a C-Kermit written Z-Modem connection script
with a Perl script running as a cron. My plan had been to contain the
C-Kermit portion in a sub, but I'm having trouble automating the
keystrokes necessary to complete the connection. For instance, after the

'call' command and then 'connect' I need to enter a login and do a send,

etc.  Anybody encounter this problem before and have ideas for a
solution?  In the past, file transfer has been by FTP, therefor
Net::FTP,
but this Z-modem creature is a barbaric one. In  a nutshell, I need to
detect
prompts from a mainframe and respond properly.

thanks,
MSH



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

Date: Wed, 24 May 2000 12:49:32 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: C-Kermit script as Perl sub
Message-Id: <Pine.GSO.4.10.10005241249020.14618-100000@user2.teleport.com>

On Wed, 24 May 2000, MSH wrote:

> I'm having trouble automating the keystrokes

Do you want the Expect module? Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 24 May 2000 16:06:05 -0400
From: MSH <MSH@question.com>
Subject: Re: C-Kermit script as Perl sub
Message-Id: <392C362D.BA40E021@question.com>

Thanks Tom...I'll take a look!

Tom Phoenix wrote:

> On Wed, 24 May 2000, MSH wrote:
>
> > I'm having trouble automating the keystrokes
>
> Do you want the Expect module? Cheers!
>
> --
> Tom Phoenix       Perl Training and Hacking       Esperanto
> Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 24 May 2000 14:09:46 -0700
From: Petri Oksanen <Petri_member@newsguy.com>
Subject: Re: C-Kermit script as Perl sub
Message-Id: <8ghgeq$992@edrn.newsguy.com>

In article <392C362D.BA40E021@question.com>, MSH says...
>>> I'm having trouble automating the keystrokes

>> Do you want the Expect module? Cheers!

>Thanks Tom...I'll take a look!

Kermit also has this functionality in its native scripting language.
You don't need Perl at all for this project.

I suggest you buy the excellent manual "Using C-Kermit" from Columbia University
and study it.
Kermit is extremely powerful, in fact, I have had wet dreams about a Kermit
module in Perl for years.

Remember: I you can't Kermit, you can't send it.


Petri Oksanen



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

Date: Wed, 24 May 2000 12:10:15 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Can't Knit Two Files Together
Message-Id: <Pine.GSO.4.10.10005241204370.14618-100000@user2.teleport.com>

On Wed, 24 May 2000, Elisa Roselli wrote:

> $curDir = `pwd`;
> chomp $curDir;

Generally, it's better (and faster!) to use the Cwd module.

> open(ENGFILE, "<$curDir/extractEng.txt"|| die "Je ne peux pas ouvrir: $!");
> open(SAMFILE,"<$curDir/a_traduire.exp"|| die "Je ne peux pas ouvrir: $!");
> open(OUT, ">$curDir/traduit2.txt"|| die "Je ne peux pas ouvrir: $!");

Oops! You're not really checking the return value from open(), as you
probably thought you were. Put the parens around the arguments to open(),
and put the "or die" part outside the parens, and you'll be fine.

> while (<SAMFILE>){
>  @sam = split (/\|/);
>    foreach $i (<ENGFILE>)

Nearly every time when this structure - reading a file inside a loop which
reads a file - shows up, it's a bug. The inner read is going to read the
entire file. Unless you re-open that file (or use seek, say), you won't
have anything to read when you get back to this point the next time
around.

Of course, the other question is about efficiency: Do you really want to
read through an entire file once for each line which is in the outer file?
Perhaps at least one of those files should be read into an array or hash.

>      print OUT $sam[0]."|$langVar
> |".$sam[2]."|$i|".$sam[4]."|".$sam[5]."|".$sam[6]."|".$sam[7]."|".$sam[8]."|
> "."\n";

I suspect that you want to learn about join(). :-)

I probably haven't solved everything for you, but I hope this gets you
closer to a solution. Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 24 May 2000 19:34:11 GMT
From: Rodney Engdahl <red_orc@my-deja.com>
Subject: Re: Can't Knit Two Files Together
Message-Id: <8gharj$qkd$1@nnrp1.deja.com>

In article <8gh1jr$rdb$1@wanadoo.fr>,
  "Elisa Roselli" <e.roselli@volusoft.com> wrote:
> Hello,
>
> I'm having some trouble getting output from two separate files and
braiding
> them together into a single file.
>
> I have a file called a_traduire.exp that consists of nine fields,
separated

<snip>


> # Here's where trouble arises. If I imbrecate the reading of ENGFILE
inside
> SAMFILE,
> # I only get the first record of SAMFILE.
> while (<SAMFILE>){
>  @sam = split (/\|/);
>    foreach $i (<ENGFILE>)
>
>      chomp $i;
>      print OUT $sam[0]."|$langVar
>
|".$sam[2]."|$i|".$sam[4]."|".$sam[5]."|".$sam[6]."|".$sam[7]."|".$sam[8]."|
> "."\n";
>    }

need to rewind ENGFILE here, or next time through you are still at EOF

> }
>
> # In an earlier version, I tried the reverse. I read ENGFILE into an
array
> which I tried to access from
> # within SAMFILE, but I only ever got the first value of the array.
>
> close(ENGFILE); etc ...
>
> ***
>


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


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

Date: Wed, 24 May 2000 12:45:47 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Can't Knit Two Files Together
Message-Id: <392C316B.623E206A@stomp.stomp.tokyo>

Elisa Roselli wrote:

> I'm having some trouble getting output from two separate files and braiding
> them together into a single file.
 
(snipped)

> 01ABS02|fr|80|Code client inexistant.||||||
> 01ABS03|fr|80|Devis client inexistant.||||||
> 01ABS04|fr|80|Client correspondant à la racine inexistant.|3|C||||

> And I want that to look like:

> 01ABS02|en|80|Customer Code does not exist.||||||
> 01ABS03|en|80|Customer Estimate does not exist.||||||
> 01ABS04|en|80|Customer corresponding to root does not exist.|3|C||||
 
> Currently, the program I have developed for this isn't working.
> Specifically, the problem I'm having is in imbricating two loops.  

(snipped)

Hello Elisa,

I have two articles for you. This is obviously the
first of two. This article shows a method of simple
substitution of French to English and writing a new
file translated to English. It also will print to
your screen, which could be changed to a third
file easily as shown in my next article for you.

You could approach this with an associative array:

Key:Value

(Key) French Expression : (Value) English Expression

if my input matches Key my output equals Value

You know how to split an associative array and
switch key / value pairs from input to output.
Using an associative array method would allow
you to develop a pseudo French to English
dictionary, based only on those expressions
you need to translate for your program.

So, look over this script and its results,
then look over my second following article.
You are clearly a skilled programmer and
might find some useful code snippets or
perhaps these two articles will inspire
you to a different approach.

Take care, some of my longer lines will
certainly word wrap in your news reader.
As you know, you might have to create
these text files by hand, upload and
set permissions. Don't forget to change
your Perl locale first line.

Godzilla!



TEST SCRIPT
___________

#!/usr/local/bin/perl

print "Content-Type:text/plain\n\n";

open (FRENCH, "french.txt"); ## optional die
@Array = <FRENCH>;
close (FRENCH);

chomp (@Array);

open (ENGLISH, ">english.txt"); ## optional die

foreach $line (@Array)
 {
  print "In French: $line\n";
  $line =~ s/\|fr\|/\|en\|/;
  $line =~ s/Code client inexistant/Customer Code does not exist/;
  $line =~ s/Devis client inexistant/Customer Estimate does not exist/;
  $line =~ s/Client correspondant à la racine inexistant/Customer
corresponding to root does not exist/;
  print ENGLISH "$line\n";
  print "In English: $line\n";
 }
close (ENGLISH);

exit;



CONTENTS OF FRENCH.TXT
_______________________

01ABS02|fr|80|Code client inexistant.||||||
01ABS03|fr|80|Devis client inexistant.||||||
01ABS04|fr|80|Client correspondant à la racine inexistant.|3|C||||


PRINTED TO ENGLISH.TXT
_______________________

01ABS02|en|80|Customer Code does not exist.|||||| 
01ABS03|en|80|Customer Estimate does not exist.|||||| 
01ABS04|en|80|Customer corresponding to root does not exist.|3|C|||| 


PRINTED TO MONITOR SCREEN
_________________________

In French: 01ABS02|fr|80|Code client inexistant.|||||| 
In English: 01ABS02|en|80|Customer Code does not exist.|||||| 
In French: 01ABS03|fr|80|Devis client inexistant.|||||| 
In English: 01ABS03|en|80|Customer Estimate does not exist.|||||| 
In French: 01ABS04|fr|80|Client correspondant à la racine
inexistant.|3|C|||| 
In English: 01ABS04|en|80|Customer corresponding to root does not
exist.|3|C||||


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

Date: Wed, 24 May 2000 12:56:01 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Can't Knit Two Files Together
Message-Id: <392C33D1.84BA35ED@stomp.stomp.tokyo>

Elisa Roselli wrote:

(snipped - see her original article)

Elisa, this is my second article of two.
You should find a previous article on
this topic. I will check to be sure both
articles post.

This method is closer to what you want.
It will open two files and, create a new
file based on the contents of those two
files, along with printing to your screen.

Caution is needed. This method relies on
french.txt and english.txt, both from my
previous article, to exist, in full. Be
sure both those files exist as shown in
my previous article; they are data bases
for this example script.

This method relies on a French version of
your data, and an English version, in two
files, respectively. I have written this
script to closer approximate what you
want, a loop which incorporates opening
of two files and manipulating data from
both, in one loop. Note my $counter. It
is the most critical component to keeping
your prints organized as you wish.

Using a combination of methods in my
previous article and methods from this
article, might just meet your needs or
perhaps you can modify and adapt selected
snippets of code to do what you want.

Same warning, watch for long lines being
word wrapped by your news reader.

I wish you luck and do sincerely hope to
have provided some useful ideas.

Godzilla!

TEST SCRIPT
____________

#!/usr/local/bin/perl

print "Content-Type:text/plain\n\n";

open (FRENCH, "french.txt"); ## optional die
@Array_French = <FRENCH>;
close (FRENCH);

chomp (@Array_French);

open (ENGLISH, "english.txt"); ## optional die
@Array_English = <ENGLISH>;
close (ENGLISH);

chomp (@Array_English);

open (OUT_FILE, ">outfile.txt"); ## optional die

$counter = 0;

foreach $line_french (@Array_French)
 {
  print "In French: $line_french\n";
  print OUT_FILE "$line_french\n";
  print "In English: $Array_English[$counter]\n";
  print OUT_FILE "$Array_English[$counter]\n";
  $counter++;
 }

close (OUT_FILE);

exit;



PRINTED TO OUTFILE.TXT
_______________________

01ABS02|fr|80|Code client inexistant.||||||
01ABS02|en|80|Customer Code does not exist.||||||
01ABS03|fr|80|Devis client inexistant.||||||
01ABS03|en|80|Customer Estimate does not exist.||||||
01ABS04|fr|80|Client correspondant à la racine inexistant.|3|C||||
01ABS04|en|80|Customer corresponding to root does not exist.|3|C||||



PRINTED TO SCREEN
_________________

In French: 01ABS02|fr|80|Code client inexistant.||||||
In English: 01ABS02|en|80|Customer Code does not exist.||||||
In French: 01ABS03|fr|80|Devis client inexistant.||||||
In English: 01ABS03|en|80|Customer Estimate does not exist.||||||
In French: 01ABS04|fr|80|Client correspondant à la racine
inexistant.|3|C||||
In English: 01ABS04|en|80|Customer corresponding to root does not
exist.|3|C||||


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

Date: Wed, 24 May 2000 13:50:26 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Can't Knit Two Files Together
Message-Id: <MPG.1395e06d71b699198aad1@nntp.hpl.hp.com>

In article <8gh1jr$rdb$1@wanadoo.fr> on Wed, 24 May 2000 18:56:40 +0300, 
Elisa Roselli <e.roselli@volusoft.com> says...

 ...

> Currently, the program I have developed for this isn't working.
> Specifically, the problem I'm having is in imbricating two loops.

Wow!  That word must be more common in French than in English.  First 
time for me, and I thought I had a large vocabulary.  :-)

> #!/usr/bin/perl -w
> #Global variables to capture the language code and find the current
> directory
> $langVar = <STDIN>;
> chomp $langVar;
> $curDir = `pwd`;
> chomp $curDir;

All that $curDir stuff isn't needed, since you could open relative to 
the current directory using only the filename.
 
> # I open a filehandle for the English text, for the French table with nine
> fields, and for an output file.
> open(ENGFILE, "<$curDir/extractEng.txt"|| die "Je ne peux pas ouvrir: $!");
> open(SAMFILE,"<$curDir/a_traduire.exp"|| die "Je ne peux pas ouvrir: $!");
> open(OUT, ">$curDir/traduit2.txt"|| die "Je ne peux pas ouvrir: $!");

Those are each wrong because of precedence.  The diagnostic is the 
alternate to a TRUE string, so is never executable.

> # Here's where trouble arises. If I imbrecate the reading of ENGFILE inside
> SAMFILE,
> # I only get the first record of SAMFILE.
> while (<SAMFILE>){
>  @sam = split (/\|/);

That does too much work, as you are interested in only the first few 
fields.  See below.

>    foreach $i (<ENGFILE>)

The big problem is here.  I presume you want to read the second file one 
line at a time to correspond to the first file, but this is a loop that 
eats up the whole file when first executed.

>      chomp $i;
>      print OUT $sam[0]."|$langVar
> |".$sam[2]."|$i|".$sam[4]."|".$sam[5]."|".$sam[6]."|".$sam[7]."|".$sam[8]."|
> "."\n";
>    }
> }

#!/usr/bin/perl -w
use strict;

chomp(my $lang_var = <STDIN>); # What's with the studlyCaps?

open ENGFILE, 'extractEng.txt' or die "Je ne peux pas ouvrir: $!";
open SAMFILE, 'a_traduire.exp' or die "Je ne peux pas ouvrir: $!";
open OUT,     '>traduit2.txt'  or die "Je ne peux pas ouvrir: $!";

while (<SAMFILE>) {
     my @sam = split /\|/, $_, 5;
     $sam[1] = $lang_var;
     chomp($sam[3] = <ENGFILE>); # This reads one line only.
     print OUT join '|' => @sam;
}

Bonne chance!

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


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

Date: Wed, 24 May 2000 14:12:58 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Can't Knit Two Files Together
Message-Id: <MPG.1395e5b6e4ac84ca98aad3@nntp.hpl.hp.com>

In article <MPG.1395e06d71b699198aad1@nntp.hpl.hp.com> on Wed, 24 May 
2000 13:50:26 -0700, Larry Rosler <lr@hpl.hp.com> says...

 ...

> #!/usr/bin/perl -w
> use strict;
> 
> chomp(my $lang_var = <STDIN>); # What's with the studlyCaps?
> 
> open ENGFILE, 'extractEng.txt' or die "Je ne peux pas ouvrir: $!";
> open SAMFILE, 'a_traduire.exp' or die "Je ne peux pas ouvrir: $!";
> open OUT,     '>traduit2.txt'  or die "Je ne peux pas ouvrir: $!";
> 
> while (<SAMFILE>) {
>      my @sam = split /\|/, $_, 5;
>      $sam[1] = $lang_var;
>      chomp($sam[3] = <ENGFILE>); # This reads one line only.
>      print OUT join '|' => @sam;
> }

In a production program, there should be an end-of-file test on the read 
from ENGFILE, just in case it is shorter than expected (which would 
probably be a fatal error).

       $sam[3] = <ENGFILE> or die "Unexpected EOF. $!";
       chomp $same[3];

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


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

Date: Wed, 24 May 2000 14:22:19 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Can't Knit Two Files Together
Message-Id: <MPG.1395e7e51fd514a98aad4@nntp.hpl.hp.com>

In article <392C33D1.84BA35ED@stomp.stomp.tokyo> on Wed, 24 May 2000 
12:56:01 -0700, Godzilla! <godzilla@stomp.stomp.tokyo> says...

 ...

> open (FRENCH, "french.txt"); ## optional die
> @Array_French = <FRENCH>;
> close (FRENCH);
> 
> chomp (@Array_French);
> 
> open (ENGLISH, "english.txt"); ## optional die
> @Array_English = <ENGLISH>;
> close (ENGLISH);
> 
> chomp (@Array_English);

Caveats for the unwary:

  Do not consider tests for failure to open files to be optional.

  Do not slurp entire files into arrays when line-at-a-time processing 
will suffice.

  Do not chomp the endings off lines if you are only going to put them 
back on immediately.

> open (OUT_FILE, ">outfile.txt"); ## optional die
> 
> $counter = 0;
> 
> foreach $line_french (@Array_French)
>  {
>   print "In French: $line_french\n";
>   print OUT_FILE "$line_french\n";
>   print "In English: $Array_English[$counter]\n";
>   print OUT_FILE "$Array_English[$counter]\n";
>   $counter++;
>  }

Unnecessary array indexes are uncouth, even in Perl 4.

perldoc -f shift

I posted a *real* solution, that deals with the contents of the files as 
well as how to find corresponding lines in each.

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


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

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


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