[19834] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2029 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 29 06:05:32 2001

Date: Mon, 29 Oct 2001 03:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1004353507-v10-i2029@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 29 Oct 2001     Volume: 10 Number: 2029

Today's topics:
    Re: Any good free syntax coloring editors for Perl on W <BROWNHIK@Syntegra.Bt.Co.Uk>
        error on host by running my script, but it works offlin <mto@kabelfoon.nl>
    Re: keyname glob? (Anno Siegel)
    Re: multiple tag replacement within a string (Anno Siegel)
        Q:Encrypt Files with Crypt::Rijndael <ralf.bender@nexgo.de>
    Re: Q:Encrypt Files with Crypt::Rijndael <Laocoon@eudoramail.com>
    Re: Q:Encrypt Files with Crypt::Rijndael <ralf.bender@nexgo.de>
    Re: Q:Encrypt Files with Crypt::Rijndael <Laocoon@eudoramail.com>
    Re: regexp and printing \0,\1 etc... <Laocoon@eudoramail.com>
    Re: regexp and printing \0,\1 etc... <bart.lateur@skynet.be>
    Re: Regexp for email address (Anno Siegel)
        selecting lines for single spacing <hugo@fractalgraphics.com.au>
    Re: selecting lines for single spacing <bernard.el-hagin@lido-tech.net>
    Re: selecting lines for single spacing <hugo@fractalgraphics.com.au>
    Re: selecting lines for single spacing <Laocoon@eudoramail.com>
    Re: selecting lines for single spacing <hugo@fractalgraphics.com.au>
    Re: selecting lines for single spacing <please@no.spam>
    Re: selecting lines for single spacing <Laocoon@eudoramail.com>
    Re: selecting lines for single spacing <bernard.el-hagin@lido-tech.net>
    Re: String Parsing... (Anno Siegel)
    Re: Tracing ["non-interactive debugging"] like in REXX? <edgue@web.de>
    Re: Tracing ["non-interactive debugging"] like in REXX? <edgue@web.de>
    Re: Tracing ["non-interactive debugging"] like in REXX? <edgue@web.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 29 Oct 2001 10:19:59 -0000
From: "Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk>
Subject: Re: Any good free syntax coloring editors for Perl on Windows?
Message-Id: <9rjank$pbt$1@pheidippides.axion.bt.co.uk>

'med programmers editor' has syntax colouring for numerous programming
languages, including perl, and allows custom schemes. Can set up buttons to
run perl, or compile java etc.

Only limitation with free version is that you can only print once without
restarting the program.

Can't remember the url, but should be easy to find.

Kevin Brownhill

"Syamala Tadigadapa" <syamalarao_tadigadapa@yahoo.com> wrote in message
news:90f30a85ef7be499d9487eeb3073830d.37422@mygate.mailgate.org...
>
> Can some body send me pointers to some really good syntax coloring editors
on
> Windows platform
> for Perl. There is good chance there are some. On Unix I suppose the
> possibility is quite remote.
> Maby be Vim works on both. But dows Vim allows you to compile the Perl
> script/module too?
>
> Please respond quickly .
> Free is better. Share ware is also Ok. But they all do expire in 30 days
or
> even less. Don't they?
>
>
> Thnaks,
> -Syamal.
>
>
> --
> Posted from 69.san-francisco-21-22rs.ca.dial-access.att.net [12.81.72.69]
> via Mailgate.ORG Server - http://www.Mailgate.ORG




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

Date: Mon, 29 Oct 2001 12:40:00 +0100
From: "MAGiC MANiAC^mTo" <mto@kabelfoon.nl>
Subject: error on host by running my script, but it works offline, why?...
Message-Id: <9rjbuj$l5t$1@news.kabelfoon.nl>


Hi there,

I try to run my script on my host.
But offline it works great, and now online I get a error...

The logfile on the host tells :

[Mon Oct 29 10:49:46 2001] [error] [client 62.45.36.181] Premature end of
script headers:
/usr/local/plesk/apache/vhosts/<hostname>/cgi-bin/links/links.cgi

What does this mean?... Is there something wrong with my script?... ?-)





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

Date: 29 Oct 2001 09:41:43 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: keyname glob?
Message-Id: <9rj88n$3ak$3@mamenchi.zrz.TU-Berlin.DE>

According to aaron smith <asmith6@nc.rr.com>:
> hi, is it possible to use keyname globs? if so can someone please post
> a small snippet of code to get me started in the right direction?

What is a "keyname glob"?  Don't expect people to understand technical
terms you just made up for the nonce.

You may be looking for something like "gep /regex/, keys %hash;", but
it's impossible to say.

Anno


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

Date: 29 Oct 2001 10:22:05 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: multiple tag replacement within a string
Message-Id: <9rjakd$6gk$2@mamenchi.zrz.TU-Berlin.DE>

According to Jeff Zucker  <jeff@vpservices.com>:
> Louis LeBlanc wrote:
> > 
> > So far, I have done the following:
> >     if (defined $not_found)
> >     {
> >       if (defined $date) $not_found =~ s/_DATE_/$date/g;
> >       else $not_found =~ s/_DATE_/unavailable/g;
> > 
> >       if (defined $server_admin) $not_found =~ s/_ADMIN_/$server_admin/g;
> >       else $not_found =~ s/_ADMIN_/unavailable/g;
> > 
> >       # Etc., . . .
> >     }
> > 
> > Which looks a little cumbersome.  Especially when you see al 8 tags
> > replaced.  Any ideas on how to make this more elegant and, hopefully,
> > more efficient?
> 
> Use the hash Luke!  Instead of variables called $date and $server_admin,
> have one hash key called configs with keys for those:
> 
> my %configs = (
>    DATE    => $date,
>    S_ADMIN => $server_admin,
>    # ... other values
> );
> my %config_string;
> if (defined $not_found) {
>    for my $key(keys %configs) { 
>         $config_string{$key} = $config{$key} or 'unavailable';

You are assuming that a valid key cannot be boolean false.  I'll
go with that assumption.

>         $not_found =~ s/_${key}_/$config_string{$key}/g;
>    }
> }
> 
> That should replace all of them at once.

It should (though I haven't tried), but you deal with the default
value ("unavailable") rather clumsily.  There's no need for the
second hash %config_string. A loop-local scalar will do:

    for my $key ( keys %configs ) {
        my $string = $config{ $key} || 'unavailable';
        $not_found =~ s/_${key}_/$string/g;
    ]


Or prepare the %config hash once so the replacement becomes
straightforward:

    $_ ||= 'unavailable' for values %configs; # vivant lvalue values!
    $not_found =~ s/_${_}_/$config_string{$_}/g for keys %configs;

Anno


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

Date: Mon, 29 Oct 2001 08:07:53 GMT
From: Ralf Bender <ralf.bender@nexgo.de>
Subject: Q:Encrypt Files with Crypt::Rijndael
Message-Id: <20011029.8075374@mis.configured.host>

Hi,

I wanna use your Perl Module Crypt::Rijndael to encrypt files of my linu=
x=20
box. I'm a perl newbie and all my tests to write a perl program won't=20=

work. Is it possible to get a sample how to encrypt and=20
decrypt a file.

regards
ralf



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

Date: Mon, 29 Oct 2001 09:26:59 +0100
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: Q:Encrypt Files with Crypt::Rijndael
Message-Id: <Xns914960216136ALaocooneudoramailcom@62.153.159.134>

There is a sample in the pod of the module :
http://search.cpan.org/doc/DIDO/Crypt-Rijndael-0.05/Rijndael.pm 


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

Date: Mon, 29 Oct 2001 10:12:48 GMT
From: Ralf Bender <ralf.bender@nexgo.de>
Subject: Re: Q:Encrypt Files with Crypt::Rijndael
Message-Id: <20011029.10124892@mis.configured.host>

Thanks for your answer.
That's what i try to do, but it won't work.

That's my perl script:
#!/usr/bin/perl -w

use Crypt::Rijndael;


 # keysize() is 32, but 24 and 16 are also possible
 # blocksize() is 16


 $cipher =3D new Crypt::Rijndael "a" x 32, Crypt::Rijndael::MODE_CBC;

 #$plaintext=3D"Ralf Bender";
 $cipher->set_iv($iv);
 $crypted =3D $cipher->encrypt($plaintext);
 # - OR -
 #$plaintext =3D $cipher->decrypt($crypted);
 print "Plain:$plaintext";
 print "Crypt:$crypted";


Here is the error output:

Name "main::iv" used only once: possible typo at test.pl line 13.
Can't locate auto/Crypt/Rijndael/set_iv.al in @INC (@INC contains:=20
/usr/lib/perl
5/5.00503/i586-linux /usr/lib/perl5/5.00503=20
/usr/lib/perl5/site_perl/5.005/i586-
linux /usr/lib/perl5/site_perl/5.005 .) at test.pl line 13

Any idea? The installation runs correct.

ralf

>>>>>>>>>>>>>>>>>> Urspr=FCngliche Nachricht <<<<<<<<<<<<<<<<<<

Am 29.10.2001, 09:26:59, schrieb Laocoon <Laocoon@eudoramail.com> zum Th=
ema=20
Re: Q:Encrypt Files with Crypt::Rijndael:


> There is a sample in the pod of the module :
> http://search.cpan.org/doc/DIDO/Crypt-Rijndael-0.05/Rijndael.pm


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

Date: Mon, 29 Oct 2001 11:49:26 +0100
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: Q:Encrypt Files with Crypt::Rijndael
Message-Id: <Xns9149784911567Laocooneudoramailcom@62.153.159.134>

Ralf Bender <ralf.bender@nexgo.de> wrote in
news:20011029.10124892@mis.configured.host: 

> Thanks for your answer.
> That's what i try to do, but it won't work.
> 
> That's my perl script:
> #!/usr/bin/perl -w
> use Crypt::Rijndael;
> 
> 
>  # keysize() is 32, but 24 and 16 are also possible
>  # blocksize() is 16

Note that # means that the rest of the line is a comment.
 
> 
>  $cipher = new Crypt::Rijndael "a" x 32, Crypt::Rijndael::MODE_CBC;
> 
>  #$plaintext="Ralf Bender";

This is a comment too and should be 
$plaintext = "Ralf Bender";

>  $cipher->set_iv($iv);
>  $crypted = $cipher->encrypt($plaintext);
>  # - OR -
>  #$plaintext = $cipher->decrypt($crypted);

A comment again..

>  print "Plain:$plaintext";
>  print "Crypt:$crypted";
> 
> 
> Here is the error output:
> 
> Name "main::iv" used only once: possible typo at test.pl line 13.

:) You can't expect it to work if you just copy/paste it..
You did not declare $iv.
Read through the whole POD ..

*snip* 
> ralf

Lao 



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

Date: Mon, 29 Oct 2001 08:38:53 +0100
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: regexp and printing \0,\1 etc...
Message-Id: <Xns914957F995F7ALaocooneudoramailcom@62.153.159.134>

> Let's imagine the following script:
> 
> ---
> #!/usr/bin/perl
> 
> $toto="totototo\0ut";

$toto = 'totototo\0ut';
 
> printf("%s\n",$toto);
> ---


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

Date: Mon, 29 Oct 2001 10:37:22 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: regexp and printing \0,\1 etc...
Message-Id: <m7bqttge0hmj5kqio7qbd69fja28n8f92f@4ax.com>

M G wrote:

>$toto="totototo\0ut";
>
>printf("%s\n",$toto);
>---
>
>How to get the printf to output
>
>totototo\0ut
>
>and not
>
>totototo^@ut
>
>I tried to escape it with regexp (s/\\/\\\\/) but visibly didn't help

Of course not. That is because the '\0' already got replaced by a null
byte in your string. EIther you prevent that conversion, as Laocoon did,
or you must replace the null byte back to a backslash plus an octal
number:

	$toto="totototo\0ut";
	$toto =~s/([\000-\037])/sprintf "\\%03o", ord $1/ge;
	print $toto;
->
	totototo\000ut

perhaps you like your octal code to be shorter, but that's not safe if
the control character is followed by a digit:

	$_ = "\00012";
	s/([\000-\037])/sprintf "\\%o", ord $1/ge;
	print;
->
	\012

A more elaborate substitution can deal with that:

	$_ = "1\0014\0028\003A";
	s/([\000-\037])(?=(\d?))/sprintf length($2)?"\\%03o":"\\%o",
	   ord $1/ge;
	print;
->
	1\0014\0028\3A

As you can see, the 3 octal digits are compressed to a minimum only if
the control character isn't followed by a digit. "\48" would be
converted safely, except that perl complains if you try to eval it:

	print "\248";
->
	Illegal octal digit '8' ignored at...
	?8

-- 
	Bart.


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

Date: 29 Oct 2001 09:35:47 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Regexp for email address
Message-Id: <9rj7tj$3ak$2@mamenchi.zrz.TU-Berlin.DE>

According to Glenn White <spam.killer@home.com_nospam>:
> "Jürgen Exner" <jurgenex@hotmail.com> wrote in
> <3bdcd35d@news.microsoft.com>: 
> 
> >Are you dealing with internal addresses *only* or may those be regular
> >Internet Email-Addresses, too? If you need regular addresses, too, then
> >I suggest to read
> >    Found in C:\Perl\lib\pod\perlfaq9.pod
> >      How do I check a valid mail address?
> >
> >It's quite enlightening
> >
> >jue
> 
> For the most part, they will be internal addresses. Unfortunately, I can 
> already forsee that Internet Email-Addresses will creap in.

In that case, your simple ;-separated scheme will break because valid
addresses can contain a ";".
 
[...]

> All I'm trying to do is to take something like the following:
> TO=FIRST-LAST;CRCG@TESTER.COM;RWBR
> 
> and turn it into:
> FIRST-LAST@TESTER.COM;CRCG@TESTER.COM;RWBR@TESTER.COM
> 
> From a C++ point of view it wouldn't be all that difficult... long winded, 
> but not that difficult. I was hoping to do it a bit more Perlish.

It looks like you just want to supply a final "@TESTER.COM" to any
string that doesn't already contain a "@".  That is indeed easy:

    join ';', map /@/ ? $_ : "$_.TESTER.COM", split /;/, substr $s, 3;

Anno



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

Date: Mon, 29 Oct 2001 16:23:40 +0800
From: hugo <hugo@fractalgraphics.com.au>
Subject: selecting lines for single spacing
Message-Id: <3BDD120C.3C21B3C5@fractalgraphics.com.au>

Hi 

I have a double-spaced input file and I would like to give the user the
option to
bundle several lines together single-spaced.  For example, if you have
the lines: 


some text here

Subsequently  here is some text

which is now double spaced

and should be single spaced. 

and some more text here


I would like to give the reader the option to put in a keyword, which in
this case would be "Subsequently" and a number of lines, say 3. This
would bundle
3 lines single spaced so that we end up with: 


some text here

Subsequently  here is some text
which is now double spaced
and should be single spaced. 

and some more text here


I would like the user to be able to repeat this process for several
keywords and number of lines. 
At the end I would like to have an output file, with all specified lines
now single-spaced and the remainder double-spaced.

I have tried to get this to work, but I am afraid I am getting rather
seriously stuck. 

Can anyone help me with this? 

Any help, particularly a code example, will be greatly appreciated.

Thanks. 

Hugo 


-- 
Dr Hugo Bouckaert
R&D Support Engineer, Fractal Graphics 
57 Havelock Street, West Perth 6005
Western Australia 6009
Tel: +618 9211 6000 Fax: +618 9226 1299
Email:hugo@fractalgraphics.com.au
Web: http://www.fractalgraphics.com.au


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

Date: Mon, 29 Oct 2001 08:31:31 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: selecting lines for single spacing
Message-Id: <slrn9tq4hk.3nk.bernard.el-hagin@gdndev25.lido-tech>

On Mon, 29 Oct 2001 16:23:40 +0800, hugo <hugo@fractalgraphics.com.au> wrote:
> Hi 
> 
> I have a double-spaced input file and I would like to give the user the
> option to
> bundle several lines together single-spaced.  For example, if you have
> the lines: 
> 
> 
> some text here
> 
> Subsequently  here is some text
> 
> which is now double spaced
> 
> and should be single spaced. 
> 
> and some more text here
> 
> 
> I would like to give the reader the option to put in a keyword, which in
> this case would be "Subsequently" and a number of lines, say 3. This
> would bundle
> 3 lines single spaced so that we end up with: 
> 
> 
> some text here
> 
> Subsequently  here is some text
> which is now double spaced
> and should be single spaced. 
> 
> and some more text here
> 
> 
> I would like the user to be able to repeat this process for several
> keywords and number of lines. 
> At the end I would like to have an output file, with all specified lines
> now single-spaced and the remainder double-spaced.
> 
> I have tried to get this to work, but I am afraid I am getting rather
> seriously stuck. 


Show us what you tried and we'll help you out with it.


Cheers,
Bernard


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

Date: Mon, 29 Oct 2001 16:52:50 +0800
From: hugo <hugo@fractalgraphics.com.au>
Subject: Re: selecting lines for single spacing
Message-Id: <3BDD18E2.444117E3@fractalgraphics.com.au>

Thanks

In my code, the problem is that I never seem to get past the conditional
statement, that is, when I get to the line if statement "if ($line[$c]
=~ /^.*$keyword\s.*/ ) {",  the first line that contains the keyword is
read in, but subsequent lines are not - print statement reveal that they
are empty. 

Here is the code. 

Note that the values for $keyword and $no_lines come from <STDIN>, but
that I would like to be able to repeat the process for several values of
$keyword and $no_lines. 

open(INFILE, "$fileconvert") || die "Could not open $fileconvert:
$!\nStopped";
       open(OUTFILE, ">test")|| die "Could not open test: $!\nStopped";
       while (defined ($in =<INFILE>)) {
       	chomp ($in);
       $line[$c] = $in;
	  if ($line[$c] =~ /^.*$keyword\s.*/ ) {
       	       	 $i = $c;
                 $stopi = ($no_lines*2)+$c; # I do this x2 as all lines
are double spaced. 
              	for ($i; $i < $stopi; $i++) {
          		$line[$c] =~ s/.*\n\n/.*\n/g;
          		$lineout[$c] = $line[$c]; 
          		$c++;
          	}
  
         }	else {
          	$lineout[$c] = $line[$c]; 
          	$c++;
         }	 	
      
         print OUTFILE $lineout[$c];
       
       }
       close (INFILE);
       close(OUTFILE);

I'll appreciate it if you can help me out with this one. 

Thanks

Hugo 

Bernard El-Hagin wrote:
> 
> On Mon, 29 Oct 2001 16:23:40 +0800, hugo <hugo@fractalgraphics.com.au> wrote:
> > Hi
> >
> > I have a double-spaced input file and I would like to give the user the
> > option to
> > bundle several lines together single-spaced.  For example, if you have
> > the lines:
> >
> >
> > some text here
> >
> > Subsequently  here is some text
> >
> > which is now double spaced
> >
> > and should be single spaced.
> >
> > and some more text here
> >
> >
> > I would like to give the reader the option to put in a keyword, which in
> > this case would be "Subsequently" and a number of lines, say 3. This
> > would bundle
> > 3 lines single spaced so that we end up with:
> >
> >
> > some text here
> >
> > Subsequently  here is some text
> > which is now double spaced
> > and should be single spaced.
> >
> > and some more text here
> >
> >
> > I would like the user to be able to repeat this process for several
> > keywords and number of lines.
> > At the end I would like to have an output file, with all specified lines
> > now single-spaced and the remainder double-spaced.
> >
> > I have tried to get this to work, but I am afraid I am getting rather
> > seriously stuck.
> 
> Show us what you tried and we'll help you out with it.
> 
> Cheers,
> Bernard

-- 
Dr Hugo Bouckaert
R&D Support Engineer, Fractal Graphics 
57 Havelock Street, West Perth 6005
Western Australia 6009
Tel: +618 9211 6000 Fax: +618 9226 1299
Email:hugo@fractalgraphics.com.au
Web: http://www.fractalgraphics.com.au


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

Date: Mon, 29 Oct 2001 10:10:27 +0100
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: selecting lines for single spacing
Message-Id: <Xns9149678083632Laocooneudoramailcom@62.153.159.134>

*snip*
$test =~ s/($keyword.+?\n)\n/$1/s for 2..$lines;

Note : $keyword and $lines are read in from the user in a loop.
$text is the whole input file.. Get it with something like :

open(TEST,"test.txt");
$text = join "",<TEST>;

Hope this helps you..

Lao


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

Date: Mon, 29 Oct 2001 17:28:08 +0800
From: hugo <hugo@fractalgraphics.com.au>
Subject: Re: selecting lines for single spacing
Message-Id: <3BDD2128.99F17E8B@fractalgraphics.com.au>

Hi

Thanks for that. 

Your code seems really good for substitution of the two newlines by one,
but surely first I have to loop through my input file to see where
$keyword matches? Could you elaborate a little on the code as how it
would like fully integrated?  

Do you mean something like this? 

open(TEST,"test.txt");
$test =~ s/($keyword.+?\n)\n/$1/s for 2..$lines;
$text = join "",<TEST>;

Would that work for multiple keywords? 

Thanks very much. 

Hugo

Laocoon wrote:
> 
> *snip*
> $test =~ s/($keyword.+?\n)\n/$1/s for 2..$lines;
> 
> Note : $keyword and $lines are read in from the user in a loop.
> $text is the whole input file.. Get it with something like :
> 
> open(TEST,"test.txt");
> $text = join "",<TEST>;
> 
> Hope this helps you..
> 
> Lao

-- 
Dr Hugo Bouckaert
R&D Support Engineer, Fractal Graphics 
57 Havelock Street, West Perth 6005
Western Australia 6009
Tel: +618 9211 6000 Fax: +618 9226 1299
Email:hugo@fractalgraphics.com.au
Web: http://www.fractalgraphics.com.au


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

Date: Mon, 29 Oct 2001 09:50:53 GMT
From: Andrew Cady <please@no.spam>
Subject: Re: selecting lines for single spacing
Message-Id: <87k7xeu68t.fsf@homer.cghm>

hugo <hugo@fractalgraphics.com.au> writes:

> In my code, the problem is that I never seem to get past the
> conditional statement, that is, when I get to the line if statement
> "if ($line[$c] =~ /^.*$keyword\s.*/ ) {", the first line that
> contains the keyword is read in, but subsequent lines are not -
> print statement reveal that they are empty.

I don't know what you're trying to do with that regex, but you can't
possibly be doing it right (that regex makes no sense at all).

If you're trying to find out if $keyword is at the end of the line,
what you want is: /${keyword}$/

If $keyword might contain regex characters like . and you want them to
act like regular characters in a substring match, use:
/\Q${keyword}\E$/

(The braces aren't necessary, they just help readability)

Please read a regex tutorial of some sort.  ^.*$ matches the entire
string, from beginning to start (you've used no modifiers).  There's
no reason to do this in a non-capturing, non-substituting regex.
Alone, it does nothing; it will match any string, including an empty
string.  In combination with other text, the match will fail on any
string; text after ^.*$ matches text *after* the end of the string,
which of course is impossible.  A .* at the end of a non-capturing,
non-substituting regex also makes no sense.  It just matches the rest
of the string, even if there's nothing left (it will never affect
whether the match succeeds).

HTH.


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

Date: Mon, 29 Oct 2001 10:50:46 +0100
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: selecting lines for single spacing
Message-Id: <Xns91496E5685D5Laocooneudoramailcom@62.153.159.134>

hugo <hugo@fractalgraphics.com.au> wrote in 
news:3BDD2128.99F17E8B@fractalgraphics.com.au:

> Hi
> 
> Thanks for that. 
> 
> Your code seems really good for substitution of the two newlines by one,
> but surely first I have to loop through my input file to see where
> $keyword matches? Could you elaborate a little on the code as how it
> would like fully integrated?  
> 
> Do you mean something like this? 
> 
> open(TEST,"test.txt");
> $test =~ s/($keyword.+?\n)\n/$1/s for 2..$lines;
> $text = join "",<TEST>;

I wrote $test instead of $text sorry. You read the input file into $text and 
then get the keyword and number of lines from the user (in a loop maybe?) 
and then substitute. I don't know what you mean with "multiple keywords" But 
you can of course read in $keyword again..

Example Code :
---------------------

#!usr/bin/perl -w
use strict;
open (INPUT,"input.txt") or die "$! Couldn't open input file";
open (OUTPUT,">output.txt") or die "$! Couldn't Open output file";
my $text = join "",<INPUT>;
close (INPUT);
my $again = 1;
while ($again ne 'n') {
print "Keyword : ";
chomp(my $keyword = <STDIN>);
print "Number of lines : ";
chomp(my $lines = <STDIN>);
$text =~ s/($keyword.+?\n)\n/$1/s for 2..$lines;
print "Again y/n ? : ";
chomp($again = <STDIN>);
}
print OUTPUT $text;
close (OUTPUT);

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

Lao


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

Date: Mon, 29 Oct 2001 10:31:48 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: selecting lines for single spacing
Message-Id: <slrn9tqbj1.3nk.bernard.el-hagin@gdndev25.lido-tech>

On Mon, 29 Oct 2001 16:23:40 +0800, hugo <hugo@fractalgraphics.com.au> wrote:
> Hi 
> 
> I have a double-spaced input file and I would like to give the user the
> option to
> bundle several lines together single-spaced.  For example, if you have
> the lines: 
> 
> 
> some text here
> 
> Subsequently  here is some text
> 
> which is now double spaced
> 
> and should be single spaced. 
> 
> and some more text here
> 
> 
> I would like to give the reader the option to put in a keyword, which in
> this case would be "Subsequently" and a number of lines, say 3. This
> would bundle
> 3 lines single spaced so that we end up with: 
> 
> 
> some text here
> 
> Subsequently  here is some text
> which is now double spaced
> and should be single spaced. 
> 
> and some more text here


Here's a quickie attempt. Not very heavily tested, just a run or two.

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

open( TEST, 'test.file' ) or die $!;

my @data = <TEST>;

chomp( my $keyword = <STDIN> );

my $amount  = <STDIN>;
   $amount -= 2;

my $flag;

foreach my $elem (@data){
  $elem =~ m/$keyword/ && $flag++;
  if( $flag ){
    if( $elem =~ m/^$/ ){
      if( $amount-- ){ next }
      else{ $flag-- }
    }
    else{ print $elem }
  }
  else{ print $elem }
}
__________________


Cheers,
Bernard


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

Date: 29 Oct 2001 10:32:33 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: String Parsing...
Message-Id: <9rjb81$6gk$3@mamenchi.zrz.TU-Berlin.DE>

According to Chris Fedde <cfedde@fedde.littleton.co.us>:
> In article <9rh7fg$b16$1@news6.svr.pol.co.uk>,
> Mercutio <mercutio@digitalrice.com> wrote:
> >
> >I can handle most things in Perl, except for string parsing. I'm going to
> >have to write functions to handle the different logical functions: AND, OR,
> >NOT, IMPLIES, IFF.
> >
> >Can anyone suggest a method of parsing the string to work the input into the
> >output?
> >
> 
> This kind of thing is typicaly done using a tokenizer and a parser.  
> The classic example of this kind of thing are the lex and yacc tools in
> the unix environment.  Perl CPAN has Parser::RecDescent and many other
                                           ^^
                                       Parse::RecDescent

Anno


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

Date: Mon, 29 Oct 2001 09:04:48 +0100
From: Edwin =?iso-8859-1?Q?G=FCnthner?= <edgue@web.de>
Subject: Re: Tracing ["non-interactive debugging"] like in REXX?
Message-Id: <3BDD0DA0.CC1BF11E@web.de>

Hi there,

Ilya Zakharevich wrote:
> Hmm???  What is the difference?

I know from your mail that you already understood
my point, but maybe it is insightful for others to
give a small example.

REXX:

D:\test>type sum.rexx
trace i
arg val1 val2
result = val1 + val2
say "result is" result

D:\test>rexx sq.rexx 10 5
     2 *-* arg val1 val2
       >>>   "10"
       >>>   "5"
     3 *-* result = val1 + val2
       >V>   "10"
       >V>   "5"
       >O>   "15"
     4 *-* say "result is" result
       >L>   "result is"
       >V>   "15"
       >O>   "result is 15"
result is 15

"Same with perl":

D:\test>set PERLDB_OPTS=NonStop=1 LineInfo=db.out AutoTrace

D:\test>type sum.pl
$val1 = $ARGV[0];
$val2 = $ARGV[1];
$result = $val1 + $val2;
print "result is $result";

D:\test>perl -d sum.pl 4 1
Default die handler restored.
result is 5
D:\test>type db.out
main::(sum.pl:1):       $val1 = $ARGV[0];
main::(sum.pl:2):       $val2 = $ARGV[1];
main::(sum.pl:3):       $result = $val1 + $val2;
main::(sum.pl:4):       print "result is $result";

snipp -----

you are right Ilya, what I want is tracing of all
read / write accesses to variables. Of course this would
create an additional overhead - but well, thats the 
nature of tracing: under normal conditions you switch
it off (because it creates an enormous overhead) but when
you have to search for errors, each single bit of information
makes you life easier. 

I have "remote" customers that invoke complicated and long-running 
scripts. If they have a problem it is very easy for me to 
debug with rexx: I just tell them to insert "trace i", to run
the script again to send me the COMPLETE trace stack. That makes
life very pleasant.
For perl it looks like we need to implement a complex mechanism
that allows as us to save the "input" that is going into each
perl expression (information gathered from a perl-xs-extension)
into a file - so that our customers can send us this "input data" ...


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

Date: Mon, 29 Oct 2001 09:11:01 +0100
From: Edwin =?iso-8859-1?Q?G=FCnthner?= <edgue@web.de>
Subject: Re: Tracing ["non-interactive debugging"] like in REXX?
Message-Id: <3BDD0F15.6C97D997@web.de>

Problem solved:

perldoc B::Concise

is what I am looking for ... 
hopefully it will run with Perl on OS/2 ....


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

Date: Mon, 29 Oct 2001 09:35:25 +0100
From: Edwin =?iso-8859-1?Q?G=FCnthner?= <edgue@web.de>
Subject: Re: Tracing ["non-interactive debugging"] like in REXX?
Message-Id: <3BDD14CD.C2C8CB0D@web.de>

> perldoc B::Concise
> 
> is what I am looking for ...
> hopefully it will run with Perl on OS/2 ....

Naw, it wont.


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.  

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 V10 Issue 2029
***************************************


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