[22222] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4443 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 21 18:10:51 2003

Date: Tue, 21 Jan 2003 15:10:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 21 Jan 2003     Volume: 10 Number: 4443

Today's topics:
    Re: Newbie - "Nobody' in sender heading? <QSPDVOFMGTUJ@spammotel.com>
        Newbie: How to remove some characters from a string (Frank San Juan)
    Re: open file for reading a part of it (Tad McClellan)
    Re: Paragraph Mode (Anno Siegel)
    Re: Paragraph Mode <tassilo.parseval@post.rwth-aachen.de>
    Re: Paragraph Mode (Anno Siegel)
    Re: Paragraph Mode <flavell@mail.cern.ch>
    Re: Paragraph Mode (Anno Siegel)
        Perl Script not working on Win NT (Eric)
    Re: Search array and return element? (jim ryan)
        Send a file w/ CGI <remccart@uiuc.edu>
        slow grep <mpapec@yahoo.com>
    Re: slow grep <skuo@mtwhitney.nsc.com>
    Re: Strange behavior for "system" call.   DOH!!! <mrohm@gtemail.net>
    Re: Text manipulation <mgjv@tradingpost.com.au>
    Re: Text manipulation <lou.moran@gellerandwind.com>
        To extract a portion of a text file (John Smith)
    Re: To extract a portion of a text file <laocoon@eudoramail.com>
    Re: To extract a portion of a text file (Tad McClellan)
    Re: To extract a portion of a text file <laocoon@eudoramail.com>
    Re: To extract a portion of a text file (Ben Morrow)
        Win32::API convert code from C (Mike Solomon)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 21 Jan 2003 22:46:07 +0100
From: Jan Korger <QSPDVOFMGTUJ@spammotel.com>
Subject: Re: Newbie - "Nobody' in sender heading?
Message-Id: <87ptqqi3c0.fsf@jan.korger>

CAMERADO <camerado@camerado.com> writes:

> Hi--
> 
> I bet you've heard this one before, but I 'm not a big perl wizard, all
> I know is that my mailing list manager uses Perl and whenever I send out
> an automated mailing it says "Nobody"/ in the sender heading...
> 
> Can anybody tell me where / how to fix this in the script?

1. de.comp.lang.perl.misc is a *German* language newsgroup.

2. I guess you mean "From: header" when you write "sender heading"

3. Most likely, your script doesn't set the From: header at all or it's
overwritten by your MTA and you are running under user "nobody". Nobody
is a common name for the user a web server uses, so if you admin your
lists via a CGI script, the script will be executed under the web servers
account which could be nobody.

xp and f'up2 comp.lang.perl.misc

Jan


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

Date: 21 Jan 2003 14:43:21 -0800
From: sanjuan10@hispavista.com (Frank San Juan)
Subject: Newbie: How to remove some characters from a string
Message-Id: <a7085a6.0301211443.20d249c1@posting.google.com>

Hello.

I'm trying to remove these characters from my string: "," and ".".

I've been playing with Regular Expressions, but I'm green:
$text =~ s/([\,\.])/\d/g;

I write '\d' in order to _D_elete the character, but I get a 'd' character.
John,Paul,Mary ---> JohndPauldMary
(and I want: JohnPaulMary)

Any experience? Thank you.


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

Date: Tue, 21 Jan 2003 13:29:23 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: open file for reading a part of it
Message-Id: <slrnb2r7sj.3p5.tadmc@magna.augustmail.com>

Christian Caron <nospam@nospam.org> wrote:

> I just can't believe it's that simple...


Perl. Ya gotta love it!


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 21 Jan 2003 19:26:36 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Paragraph Mode
Message-Id: <b0k6tc$99b$1@mamenchi.zrz.TU-Berlin.DE>

Tad McClellan <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
> Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote:
> > Also sprach Steve C:
> 
> >> is
> >> there a more "technically correct" term for this 'paragraph mode' ??
> > 
> > I thought it would be mentioned in perlvar, under $/, but it's not very
> > clear there either.
> 
> 
> The description in perlvar.pod is indeed sub-optimal.

You think so?  Well, the reference to AWK has certainly become obsolete,
but otherwise it's all there, except for the words "paragraph mode".
Working those in would be a simple step in the right direction.  

> The resourceful Perl programmer will eventually turn to grepping
> the *.pod files when perldoc'ing with several terms doesn't work:
> 
>    grep 'paragraph mode' *.pod
> 
> It finds 2 hits (5.8.0), neither of which describes what it is.
> 
> The docs use the term twice, but never define it!
> 
> There is definitely room for improvement there...

Perhaps in form of a FAQ?  Here's a quick attempt:

    What is paragraph mode?

    In paragraph mode, you change Perl's idea of what is a line so that
    on each input operation an entire paragraph is read where you would
    normally expect a single line.  You enable paragraph mode by setting
    the input separator $/ to an empty string:

        $/ = '';

    (See $/ in perlvar for other possibilities.)  In paragraph mode, any
    sequence of empty lines, that is a sequence of two or more linefeeds,
    terminates a chunk of input.  That is slightly different from setting
    the input separator to two linefeeds because in paragraph mode any
    number of trailing empty lines belong to the previous paragraph.

Hmm... did I say "quick attempt"?  This has taken longer than I care to
admit, and it doesn't mention IO-disciplines and (possibly) IO:: methods.

Anno


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

Date: 21 Jan 2003 20:10:00 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Paragraph Mode
Message-Id: <b0k9eo$7fj$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Anno Siegel:

> Tad McClellan <tadmc@augustmail.com> wrote in comp.lang.perl.misc:

>> The description in perlvar.pod is indeed sub-optimal.
> 
> You think so?  Well, the reference to AWK has certainly become obsolete,
> but otherwise it's all there, except for the words "paragraph mode".

Which I think is the crucial point here. My irritation came from the
fact that I was very familiar with the expression "paragraph mode" and
then had to realize (after not finding it in the perldocs) that I had no
idea where I picked it up. In the sense of the social term of
"uncertainty avoidance" this is what made it sub-optimal for me. :-) 

Would you guess it where paragraph mode actually shows up in the
perldocs? It's in perlrun in the description of the -0 switch (which
also contains a mild reference to $/).

> Working those in would be a simple step in the right direction.  
> 
>> The resourceful Perl programmer will eventually turn to grepping
>> the *.pod files when perldoc'ing with several terms doesn't work:
>> 
>>    grep 'paragraph mode' *.pod
>> 
>> It finds 2 hits (5.8.0), neither of which describes what it is.
>> 
>> The docs use the term twice, but never define it!
>> 
>> There is definitely room for improvement there...
> 
> Perhaps in form of a FAQ?  Here's a quick attempt:

But is it a FAQ? I think working around an omission in perlvar.pod by
adding an entry to the FAQs doesn't seem quite right.

[...]

> Hmm... did I say "quick attempt"?  This has taken longer than I care to
> admit, and it doesn't mention IO-disciplines and (possibly) IO:: methods.

At least it's more work than mending perlvar as you realized as well.
;-)

Tassilo
-- 
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;


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

Date: 21 Jan 2003 20:48:43 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Paragraph Mode
Message-Id: <b0kbnb$cfe$1@mamenchi.zrz.TU-Berlin.DE>

Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote in comp.lang.perl.misc:
> Also sprach Anno Siegel:
> 
> > Tad McClellan <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
> 
> >> The description in perlvar.pod is indeed sub-optimal.
> > 
> > You think so?  Well, the reference to AWK has certainly become obsolete,
> > but otherwise it's all there, except for the words "paragraph mode".
> 
> Which I think is the crucial point here. My irritation came from the
> fact that I was very familiar with the expression "paragraph mode" and
> then had to realize (after not finding it in the perldocs) that I had no
> idea where I picked it up. In the sense of the social term of
> "uncertainty avoidance" this is what made it sub-optimal for me. :-) 
> 
> Would you guess it where paragraph mode actually shows up in the
> perldocs? It's in perlrun in the description of the -0 switch (which
> also contains a mild reference to $/).

I know, I looked it up too :)

> > Working those in would be a simple step in the right direction.  
> > 
> >> The resourceful Perl programmer will eventually turn to grepping
> >> the *.pod files when perldoc'ing with several terms doesn't work:
> >> 
> >>    grep 'paragraph mode' *.pod
> >> 
> >> It finds 2 hits (5.8.0), neither of which describes what it is.
> >> 
> >> The docs use the term twice, but never define it!
> >> 
> >> There is definitely room for improvement there...
> > 
> > Perhaps in form of a FAQ?  Here's a quick attempt:
> 
> But is it a FAQ? I think working around an omission in perlvar.pod by
> adding an entry to the FAQs doesn't seem quite right.

Well, the question is perhaps not frequently asked in so many words
(few FAQs are), but "use paragraph mode" is often (part of) the answer
to a problem that is otherwise posed.  Placing "paragraph mode" in a
FAQ title would give it some prominence, more than hiding it in the
description of $/ in perlvar.  OTOH, maybe slipping "paragraph mode"
into perlvar is all we want.

> [...]
> 
> > Hmm... did I say "quick attempt"?  This has taken longer than I care to
> > admit, and it doesn't mention IO-disciplines and (possibly) IO:: methods.
> 
> At least it's more work than mending perlvar as you realized as well.
> ;-)

Yes, though re-wording the core documentation requires a much more
careful hand than adding a FAQ.  That stuff is a language feature :)

Anno


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

Date: Tue, 21 Jan 2003 21:32:18 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Paragraph Mode
Message-Id: <Pine.LNX.4.40.0301212122050.19990-100000@lxplus073.cern.ch>

On Jan 21, Tassilo v. Parseval inscribed on the eternal scroll:

> But is it a FAQ? I think working around an omission in perlvar.pod by
> adding an entry to the FAQs doesn't seem quite right.

I'd certainly vote for making the documentation the first priority.

As for FAQ, maybe it isn't a question that's frequently asked.  It
wouldn't be the first time that an answer which is often enough needed
was smuggled into the FAQs with a somewhat artifical question to hang
it on.  ;-)  But I still think it's perlvar to tackle first.

To start however, it seems a consensus is needed on whether the term
"Paragraph mode" covers one or both of $/ = ''; and $/ = "\n\n"; The
current perlvar explains well enough what each of them does, but omits
to give a name to them.



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

Date: 21 Jan 2003 21:33:08 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Paragraph Mode
Message-Id: <b0keak$eak$1@mamenchi.zrz.TU-Berlin.DE>

Alan J. Flavell <flavell@mail.cern.ch> wrote in comp.lang.perl.misc:
> On Jan 21, Tassilo v. Parseval inscribed on the eternal scroll:

[about $/ in perlvar]

> To start however, it seems a consensus is needed on whether the term
> "Paragraph mode" covers one or both of $/ = ''; and $/ = "\n\n"; The
> current perlvar explains well enough what each of them does, but omits
> to give a name to them.

That question never occurred to me.  Right-thinking Perlers know that
$/ = ''; is the true paragraph mode, anything else is ersatz.  I think
a case can be made for that belief.

Anno


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

Date: 21 Jan 2003 14:53:43 -0800
From: electo7366@aol.com (Eric)
Subject: Perl Script not working on Win NT
Message-Id: <fc8f04ad.0301211453.49b599da@posting.google.com>

I have a perl script that works on Linux, Unix, and Win ME with
Apache. I need it to run on Win NT/2000 web server with IIS 5.0.

After going through the script I have determined it is not opening a
file using the open command. I've tried using the standard unix file
paths /cgi-bin/file.txt as well as the full disk path C:\directory\
and C:/directory/ none work. The file does not return an error.

Does anyone know how to fix this? Is it the file path or a problem
with the perl open command?

Thank you!!


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

Date: 21 Jan 2003 13:06:07 -0800
From: ryan@jimryan.com (jim ryan)
Subject: Re: Search array and return element?
Message-Id: <d220d0c9.0301211306.18d6b016@posting.google.com>

tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnb2qq3g.2s8.tadmc@magna.augustmail.com>...
> jim ryan <ryan@jimryan.com> wrote:
> 
> > If I issue a system command that returns multple lines into an array,
> 
> 
> You can't issue a system() command that returns multiple lines...

I'm working in NT.  Don't know if this makes a difference, but I do it
all the time...@array = `some system command`;

> 
> 
> > how do I subsequently search through that array for a string and
> 
> 
>    perldoc -f grep
> 
>       my @matches = grep /a string/, @array;

I'll look at that.  Thank you
> 
> 
> > return all the element numbers where that string occurs?
> 
> 
>    my @match_indexes = grep $array[$_] =~ /a string/, 0..$#array;
> 
> 
> But if you need the indexes, rather than the values of the elements,
> you've probably made a mistake in the design of your code.
> 
> You seldom need to do explicit indexing in idiomatic Perl.

Thanks for all the quick replies.  This gives me something to go on...

Jim


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

Date: Tue, 21 Jan 2003 13:58:34 -0600
From: Ryan <remccart@uiuc.edu>
Subject: Send a file w/ CGI
Message-Id: <mAhX9.13464$Vf3.143953@vixen.cso.uiuc.edu>

I am using perl and CGI and want to send a file on the local server to 
be downloaded.  The file does not have a web path and therefore I cannot 
just point to it and let the MIME type and the browser take care of it. 
  I tried the following code, but it doesn't work especially on Mozilla. 
  Any help or suggestions would be greatly appreciated.

---
sub download {

	my $path = "/data/";
	my $fname = $FORM{file};
	my $cwd = '';
	if ($FORM{CWD}) { $cwd = "$FORM{CWD}/"; }
	my $filepath = "$path$cwd$fname";
	my $size = -s $filepath;
	my $buff;

	print "Content-type: application/octet-stream\r\n";
	print "Content-Length: $size\r\n";
	print "Content-disposition: attachment;filename=$fname\r\n\r\n";
	
	open(FILE, "<$filepath") || die;
	binmode FILE;
	binmode STDOUT;
	while (read FILE, $buff, 1024) {
  		print $buff;
	}
	close(FILE);
	
	exit(0);
}



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

Date: Tue, 21 Jan 2003 20:08:53 +0100
From: Matija Papec <mpapec@yahoo.com>
Subject: slow grep
Message-Id: <2m6r2vongjorfk38kk9bbdad8icdb6cg3m@4ax.com>


I did some benchmarks and was surprised by grep slow execution time(am I
doing something wrong?)

Perl is 5.6.1

-=-=-=-=-=-=-
#!/usr/bin/perl
use Benchmark;

@arr = qw/tato fato mato gato mato3/;

Benchmark::cmpthese(50000,
{
a => sub{ &sub1 },
b => sub{ &sub3 },
});


sub sub1 {

#push @{ qw(target rest)[/^mato/ ? 0:1] }, $_ for @arr;
#/^mato/ ? push @target, $_ : push @rest, $_ for @arr;
my @rest=();
!/^mato/ ? push @rest, $_ : 0 for @arr;

}

sub sub3 {

my @rest = grep {!/^mato/} @arr;
  
}
-=-=-=-=-=-=-

Benchmark: timing 50000 iterations of a, b...
         a:  1 wallclock secs ( 0.73 usr +  0.00 sys =  0.73 CPU) @
68493.15/s (n=50000)
         b:  1 wallclock secs ( 0.91 usr +  0.00 sys =  0.91 CPU) @
54945.05/s (n=50000)
     Rate    b    a
b 54945/s   -- -20%
a 68493/s  25%   --
 -  



-- 
Matija


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

Date: Tue, 21 Jan 2003 12:23:19 -0800
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: slow grep
Message-Id: <Pine.GSO.4.21.0301211220140.24529-100000@mtwhitney.nsc.com>

On Tue, 21 Jan 2003, Matija Papec wrote:

> 
> I did some benchmarks and was surprised by grep slow execution time(am I
> doing something wrong?)
> 
> Perl is 5.6.1
> 
> -=-=-=-=-=-=-
> #!/usr/bin/perl
> use Benchmark;
> 
> @arr = qw/tato fato mato gato mato3/;
> 
> Benchmark::cmpthese(50000,
> {
> a => sub{ &sub1 },
> b => sub{ &sub3 },
> });
> 
> 
> sub sub1 {
> 
> #push @{ qw(target rest)[/^mato/ ? 0:1] }, $_ for @arr;
> #/^mato/ ? push @target, $_ : push @rest, $_ for @arr;
> my @rest=();
> !/^mato/ ? push @rest, $_ : 0 for @arr;
> 
> }
> 
> sub sub3 {
> 
> my @rest = grep {!/^mato/} @arr;
>   
> }

(Benchmark results snipped).



Return value of the two subroutines aren't the same:

my @you_say_potato = sub1();
my @i_say_potato = sub3();
print "@you_say_potato : @i_say_potato";

Add 'return @rest;' at the end of sub1 and try again.

-- 
Cheers,
Steven



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

Date: Tue, 21 Jan 2003 11:21:54 -0800
From: MR <mrohm@gtemail.net>
Subject: Re: Strange behavior for "system" call.   DOH!!!
Message-Id: <3E2D9DD2.5090006@gtemail.net>


Sorry for wasting time.  I was forgetting to
close the $cmd_file before calling "system".
After the script exited it got closed, and of
course it worked from the shell.

All is better now.





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

Date: Wed, 22 Jan 2003 09:35:11 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Text manipulation
Message-Id: <slrnb2riov.7m2.mgjv@martien.heliotrope.home>

On Tue, 21 Jan 2003 09:13:16 -0500,
	Lou Moran <lou.moran@gellerandwind.com> wrote:
> On Tue, 21 Jan 2003 12:31:04 +1100, Martien Verbruggen
><mgjv@tradingpost.com.au> wrote:
> 
>>Are you sure you have that right? Your example data doesn't have double
>>quotes,
> 
> Sorry I had already "fixed" that

And you did take into a account that some of the names might have
apostrophes in them?

>>That is too vague. Both of them have 4 fields. Is the presence of an
>>empty last field enough to trigger this knowledge? How are we supposed
>>to figure out whether or not there is a second address line without
>>knowing how this thing got populated in the first place?
> 
> Regrettably this (and 13,000 more lines just like them) is what they
> handed me.  The come from Crystal Reports saved as .csv. 

Then you need to ask the people who create the report some questions. 

1a) What does it mean if there is an empty last field?
1b) If there is an empty last field, does that mean there is no second
    address line?
1c) If so, then why the **** didn't you create that empty field in the
    right place?
2) Why did you guys even create such crappy data in the first place.
   Crystal Reports is not great, but it isn't that bad.

Once they have answered those, you can proceed. As long as you don't
know what exactly tells you that there is no second address field, you
can't. he only thing you could do then is start to guess whether the
third field looks like an address or a city/zip. Potentials for mistake.

Say.... You didn't introduce that empty last field yourself by any
chance, did you? If so, I am going to berate you and tell you to always
send the _original_ data to work with. 

Martien
-- 
                        | Yes; Windows is great for running &
Martien Verbruggen      | developing viruses, for instance.  It's also
                        | very popular, but then again, so is the
                        | common cold. -- Dave Hinz


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

Date: Tue, 21 Jan 2003 17:58:29 -0500
From: Lou Moran <lou.moran@gellerandwind.com>
Subject: Re: Text manipulation
Message-Id: <hpjr2vc6e7bkmgs7nlu41pph9h5o8ql840@4ax.com>

On Wed, 22 Jan 2003 09:35:11 +1100, Martien Verbruggen
<mgjv@tradingpost.com.au> wrote:

>On Tue, 21 Jan 2003 09:13:16 -0500,
>	Lou Moran <lou.moran@gellerandwind.com> wrote:
>> On Tue, 21 Jan 2003 12:31:04 +1100, Martien Verbruggen
SNIP
>And you did take into a account that some of the names might have
>apostrophes in them?
>
<shame> no </shame>

SNIP
>Then you need to ask the people who create the report some questions. 
>
SNIP

Ultimately I simply ran a crystal report against the database and
configured a "report" that would output what _I_  wanted and expected.
In hindsight I could have tried to hit the DB with DBI and done the
same but think of what mess that would have been

>Say.... You didn't introduce that empty last field yourself by any
>chance, did you? If so, I am going to berate you and tell you to always
>send the _original_ data to work with. 

That was how I got it, except that it had " which I changed to '.

>
>Martien

Thanks.

--
There's more than one way to do it, but only some of them work


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

Date: 21 Jan 2003 12:54:16 -0800
From: clearguy02@yahoo.com (John Smith)
Subject: To extract a portion of a text file
Message-Id: <500f84f3.0301211254.33f5c287@posting.google.com>

Hi all,

I am working on a perl script.

I have below text file (C:\\BobTest\\test.txt):

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(start of the file)
   Component    : Main TestPiece
    Language        : C++
   Creation Date   : 20-03-2002
      Test Key :                       hi_hello_there
                                       test_log_long_one
                                       hello_short_my_song
    How are you doing there?

      Copyright (C) Bla bla bla,  All Rights Reserved

This software is for only the test purposes.

      Test cases :                       samson_hello
                                       robert_log_hithere
                                       smith_short_my_song
#ifndef  TEST_H
#endif
 .......
 ..........            
#endif 
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (end of file)



Now, I want exactly the below segment as the output (only the first
"Test cases" field and its values in the file. It should ignore the
any other "Test cases" that appear later in the file).

Example of the output:
--------------------------------------------------------------------
Test cases :                           hi_hello_there
                                       test_log_long_one
                                       hello_short_my_song
-----------------------------------------------------------------------

The next field after the "Test cases" field can be any text (in this
case, it is a sentence "How are you doing there") or even a blank
line. I am sure that the next sentence after the last value of the
"Test cases" field doen't have the underscore symbol in it.

The values of "Test cases" field can be more than one and but each of
them is only one word.  I don't want anything after the last value of
the Test Key.

I am confused in choosing a end delimer(since it always changes), if I
want to use the range operator. I am sure of only the start delimeter
i.e. "Test cases".


Is there an efficient way of achieving this task? I am using " next
unless (/^\s*Test/...);"  But Iam not getting the result I want.

Thanks in advance,
BS


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

Date: Tue, 21 Jan 2003 22:53:49 +0100
From: Lao Coon <laocoon@eudoramail.com>
Subject: Re: To extract a portion of a text file
Message-Id: <Xns930AE8F6852CFLaocoon@62.153.159.134>

clearguy02@yahoo.com (John Smith) wrote in 
news:500f84f3.0301211254.33f5c287@posting.google.com:

> Hi all,
> 
> I am working on a perl script.
> 
> I have below text file (C:\\BobTest\\test.txt):
> 
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(start of the file)
>    Component    : Main TestPiece
>     Language        : C++
>    Creation Date   : 20-03-2002
>       Test Key :                       hi_hello_there
>                                        test_log_long_one
>                                        hello_short_my_song
>     How are you doing there?
> 
>       Copyright (C) Bla bla bla,  All Rights Reserved
> 
> This software is for only the test purposes.
> 
>       Test cases :                       samson_hello
>                                        robert_log_hithere
>                                        smith_short_my_song
> #ifndef  TEST_H
> #endif
> .......
> ..........            
> #endif 
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (end of file)
> 
> 
> 
> Now, I want exactly the below segment as the output (only the first
> "Test cases" field and its values in the file. It should ignore the
> any other "Test cases" that appear later in the file).
> 
> Example of the output:
> --------------------------------------------------------------------
> Test cases :                           hi_hello_there
>                                        test_log_long_one
>                                        hello_short_my_song
> -----------------------------------------------------------------------
> 
> The next field after the "Test cases" field can be any text (in this
> case, it is a sentence "How are you doing there") or even a blank
> line. I am sure that the next sentence after the last value of the
> "Test cases" field doen't have the underscore symbol in it.

open(INPUT,"C:\\BobTest\\test.txt") or die "error opening file : $!";
my $file, $i;
$i = 0;
while(<INPUT>) {
	if($i == 0) { next unless /_/ }
	else { last if ! /_/ }
	$file .= $_;
	$i = 1;
}

$file =~ s/.+Test/Test/s; # nm this if there is no underscore in the     
	    	    	    	  # beginning of the file either
print $file;


HTH
Lao



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

Date: Tue, 21 Jan 2003 16:08:53 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: To extract a portion of a text file
Message-Id: <slrnb2rh7l.4av.tadmc@magna.augustmail.com>

John Smith <clearguy02@yahoo.com> wrote:

> I have below text file (C:\\BobTest\\test.txt):

[snipped. repeated in __DATA__ below]


> Now, I want exactly the below segment as the output (only the first
> "Test cases" field and its values in the file. It should ignore the
> any other "Test cases" that appear later in the file).

Then you should probably _have_ other ones later in the
file so you can test if that happens or not.


> Example of the output:
> --------------------------------------------------------------------
> Test cases :                           hi_hello_there
>                                        test_log_long_one
>                                        hello_short_my_song
> -----------------------------------------------------------------------


Huh?

It is "Test cases" or "Test Key"?


> The next field after the "Test cases" field can be any text (in this
> case, it is a sentence "How are you doing there") 


Huh?

It is "Test cases" or "Test Key"?


> or even a blank
> line. I am sure that the next sentence after the last value of the
> "Test cases" field doen't have the underscore symbol in it.
        ^^^^^
        ^^^^^ yet again

Do the values that you do want always have an underscore in them?


> The values of "Test cases" field can be more than one and but each of
                      ^^^^^
> them is only one word.  I don't want anything after the last value of
> the Test Key.
           ^^^

Sheesh!


> I am confused 


Me too.


> in choosing a end delimer(since it always changes), if I
> want to use the range operator. I am sure of only the start delimeter
> i.e. "Test cases".
             ^^^^^

Key.


> Is there an efficient way of achieving this task?

If the values of interest always have underscores in them:

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

while ( <DATA> ) {
   last if /^\s*Test Key :/;
}
print;
while ( <DATA> ) {
   last unless /_/;
   print;
}


__DATA__
   Component    : Main TestPiece
    Language        : C++
   Creation Date   : 20-03-2002
      Test Key :                       hi_hello_there
                                       test_log_long_one
                                       hello_short_my_song
    How are you doing there?

      Copyright (C) Bla bla bla,  All Rights Reserved

This software is for only the test purposes.

      Test cases :                       samson_hello
                                       robert_log_hithere
                                       smith_short_my_song
#ifndef  TEST_H
#endif
 .......
 ..........
#endif
 ------------------------------


A better solution might be to keep going until you find a line 
that is not at the same level of indent as the Key line:

 ------------------------------
my $indent;
while ( <DATA> ) {
   $indent = length($1), last if /^(\s*Test Key :\s*)/;
}
print;

while ( <DATA> ) {
   last unless /^\s{$indent}\S/;
   print;
}
 ------------------------------


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 21 Jan 2003 23:12:48 +0100
From: Lao Coon <laocoon@eudoramail.com>
Subject: Re: To extract a portion of a text file
Message-Id: <Xns930AEC2E18734Laocoon@62.153.159.134>

Lao Coon <laocoon@eudoramail.com> wrote in news:Xns930AE8F6852CFLaocoon@
62.153.159.134:

> clearguy02@yahoo.com (John Smith) wrote in 
> news:500f84f3.0301211254.33f5c287@posting.google.com:
> 
>> Hi all,
>> 
>> I am working on a perl script.
>> 
>> I have below text file (C:\\BobTest\\test.txt):
>> 
>> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(start of the file)
>>    Component    : Main TestPiece
>>     Language        : C++
>>    Creation Date   : 20-03-2002
>>       Test Key :                       hi_hello_there
>>                                        test_log_long_one
>>                                        hello_short_my_song
>>     How are you doing there?
>> 
>>       Copyright (C) Bla bla bla,  All Rights Reserved
>> 
>> This software is for only the test purposes.
>> 
>>       Test cases :                       samson_hello
>>                                        robert_log_hithere
>>                                        smith_short_my_song
>> #ifndef  TEST_H
>> #endif
>> .......
>> ..........            
>> #endif 
>> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (end of file)
>> 
>> 
>> 
>> Now, I want exactly the below segment as the output (only the first
>> "Test cases" field and its values in the file. It should ignore the
>> any other "Test cases" that appear later in the file).
>> 
>> Example of the output:
>> --------------------------------------------------------------------
>> Test cases :                           hi_hello_there
>>                                        test_log_long_one
>>                                        hello_short_my_song
>> 
-----------------------------------------------------------------------
>> 
>> The next field after the "Test cases" field can be any text (in this
>> case, it is a sentence "How are you doing there") or even a blank
>> line. I am sure that the next sentence after the last value of the
>> "Test cases" field doen't have the underscore symbol in it.
> 
> open(INPUT,"C:\\BobTest\\test.txt") or die "error opening file : $!";
> my $file, $i;
> $i = 0;
> while(<INPUT>) {
>      if($i == 0) { next unless /_/ }

should be : if($i == 0) { next unless /^\s+Test/ }
sry my mistake..

>      else { last if ! /_/ }
>      $file .= $_;
>      $i = 1;
> }

$file =~ s/^\s+//; # remove starting whitespace

>
> print $file;
> 
> 
> HTH
> Lao
> 



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

Date: Tue, 21 Jan 2003 22:43:42 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: To extract a portion of a text file
Message-Id: <b0kieu$stc$1@wisteria.csv.warwick.ac.uk>

clearguy02@yahoo.com (John Smith) wrote:
>Hi all,
>
>I am working on a perl script.
>
>I have below text file (C:\\BobTest\\test.txt):
>
>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(start of the file)
>   Component    : Main TestPiece
>    Language        : C++
>   Creation Date   : 20-03-2002
>      Test Key :                       hi_hello_there
>                                       test_log_long_one
>                                       hello_short_my_song
>    How are you doing there?
>
>      Copyright (C) Bla bla bla,  All Rights Reserved
>
>This software is for only the test purposes.
>
>      Test cases :                       samson_hello
>                                       robert_log_hithere
>                                       smith_short_my_song
>#ifndef  TEST_H
>#endif
>.......
>..........            
>#endif 
>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (end of file)
>
>
>
>Now, I want exactly the below segment as the output (only the first
>"Test cases" field and its values in the file. It should ignore the
>any other "Test cases" that appear later in the file).
>
>Example of the output:
>--------------------------------------------------------------------
>Test cases :                           hi_hello_there
>                                       test_log_long_one
>                                       hello_short_my_song
>-----------------------------------------------------------------------
>
>The next field after the "Test cases" field can be any text (in this
>case, it is a sentence "How are you doing there") or even a blank
>line. I am sure that the next sentence after the last value of the
>"Test cases" field doen't have the underscore symbol in it.
>
>The values of "Test cases" field can be more than one and but each of
>them is only one word.  I don't want anything after the last value of
>the Test Key.
>
>I am confused in choosing a end delimer(since it always changes), if I
>want to use the range operator. I am sure of only the start delimeter
>i.e. "Test cases".
>
>
>Is there an efficient way of achieving this task? I am using " next
>unless (/^\s*Test/...);"  But Iam not getting the result I want.

What I would try first here, I think, is

1. Expand tabs to spaces (use Text::Tabs).

2. Find the first line you want, and work out what the indentation of the
test case is. Something like

$_ = <> until /^\s*Test cases:\s*(\S*)/;
my $indent = $-[1];  # see perldoc perlvar

3, Carry on reading lines until you hit one which doesn't start with the right
indent.

my @cases;
do {
  push @cases, $1;
  $_ = <>;
} while (/^[ ]{$indent}(\S+)/);

Note this is untested. Oh, and of course, you'll probably actually want to
expand each line as you read it, rather than try and do them all at the start.

Ben


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

Date: 21 Jan 2003 12:09:01 -0800
From: mike_solomon@lineone.net (Mike Solomon)
Subject: Win32::API convert code from C
Message-Id: <56568be5.0301211209.83e30f5@posting.google.com>

I need to make some API calls using Win32:API to access QAS 

I have some sample C code but I am not a C programmer

If anyone one could give me some hints on how to write the following
code in Perl I would be very grateful

It is the API calls that I have no idea about

Thanks

Here is the part of the C code I have been given:

    /* Open the QuickAddress Pro databases */
    iCode = QAPro_Open (psIniFile, psIniSect);
    if (iCode != 0)
    {
        ReportError ("Initialisation warning", iCode);
        iCode = 0;
    }
    if (iCode == 0)
    {
        /* Set timeout if given as a parameter */
        if (lTimeout)
        {
            QAPro_SetTimeout (lTimeout);
        }

        /* Install an event handler */
        QAPro__SetEventHandler (ShowProgress);

        /* Banner */
        printf ("    ****************************************\n");
        printf ("    *    QuickAddress Pro Test Harness     *\n");
        printf ("    *  Copyright (c) QAS Systems Ltd 1998  *\n");
        printf ("    ****************************************\n\n");

        /* Loop whilst user enters valid search string */
        while (UserInput (PROMPT, NULL, sSearch) && *sSearch != '\0')
        {
            /* > means change to new config section */
            if (*sSearch == '>')
            {
                ReportError ("Error", QAPro_ChangeFormat (sSearch +
1));
            }
            /* If user typed '=' then display system */
            /* information else perform the search */
            else if (*sSearch == '=')
            {
                for (iLineNo = 0;
                    QASystemInfo (iLineNo, sMsg, sizeof(sMsg)) == 0;
                    iLineNo++)
                {
                    while ((psTab = strchr (sMsg, '\t')) != NULL)
                    {
                        *psTab = ' ';
                    }
                    printf (sMsg);
                    printf ("\n");
                }
                QASystemInfo (-1, NULL, 0);
            }
            else
            {
                /* Search */
                iCode = QAPro_Search (sSearch);
                ReportError ("Search result", iCode);
                if ((iCode >= 0) || (iCode == qaerr_POSTCODERECODED))
                {
                    /* Allow the user to select the address and */
                    /* display the result */
                    if ((iCode = SelectAddress (sAddress, sizeof
(sAddress))) == 0
                        || iCode == qaerr_OVERFLOW
                        || iCode == qaerr_FIELDTRUNCATED)
                    {
                        printf ("\nSelected Address:\n");
                        printf
("========================================\n");
                        printf (sAddress);
                        printf
("========================================\n");
                    }
                }

                /* Free any resources grabbed during search */
                QAPro_EndSearch ();
            }

Regards


Mike Solomon


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

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


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