[17762] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5182 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 22 14:10:33 2000

Date: Fri, 22 Dec 2000 11: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)
Message-Id: <977512212-v9-i5182@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 22 Dec 2000     Volume: 9 Number: 5182

Today's topics:
    Re: opensource C/C++ compiler for Win32? <nagle@animats.com>
    Re: problem with awk in perl script (Andrew N. McGuire)
    Re: problem with awk in perl script <mischief@velma.motion.net>
    Re: regexp question <sportbikeworld@my-deja.com>
    Re: regexp question <sportbikeworld@my-deja.com>
    Re: regexp question <abe@ztreet.demon.nl>
    Re: regular expr. (Tad McClellan)
    Re: Sorting hash (Tad McClellan)
    Re: Splitting text, but not individual words <Jerome.Abela@free.fr>
        Strange CGI.pm behaviour (EED)
    Re: Use PERL or Java? Which is faster? <brannon@lnc.usc.edu>
        vec seems to need a tmp in my .pm file?? (Richard Zilavec)
    Re: Why are multiple zeroes true? (Abigail)
    Re: Why are multiple zeroes true? (Ilya Zakharevich)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 22 Dec 2000 10:11:23 -0800
From: John Nagle <nagle@animats.com>
Subject: Re: opensource C/C++ compiler for Win32?
Message-Id: <3A43994B.4DFC4B9E@animats.com>

Noel McLoughlin wrote:
> 
> Is there any way to get  gcc for a win32 machine.

   start at http://www.fsf.org/software/gcc/gcc.html
> 
> I want to try and get the necessary developer utilities on my
> NT4 pc so I can build Perl from source (instead of binarys.)

   That's great!  For those of us who don't want the ActiveState
version of Perl, this is needed.  Keep us posted on how this goes.
You might want to distribute the result on SourceForge.
Right now, there's no win32 binary for standard Perl.  The
ActiveState version has lots of Microsoft-specific extensions and
requires IE 5, etc, so it's not a standard distribution.

					John Nagle
					Animats


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

Date: 22 Dec 2000 10:26:25 -0600
From: anmcguire@ce.mediaone.net (Andrew N. McGuire)
Subject: Re: problem with awk in perl script
Message-Id: <86g0jgcthq.fsf@hawk.ce.mediaone.net>

>>>>> "NL" == Nikos Laoutaris <laoutaris@di.uoa.gr> writes:

NL> Hello evrybody in the numerous newsgroups that i am posting
NL> I have a problem with a rather simple awk command that i am issuing from
NL> inside a perl script using the system() call.

NL> The awk command is

NL> awk '{print $10,$1}' statdata.dat

perl -pale '$_="@F[10,0]"' statdata.dat

no need for awk.

NL> which simply prints the 10th and the 1st token from each line of
NL> statdata.dat (tubullar format). When i run the command from the command
NL> prompt of solaris it returns as expected.

NL> I try to call awk from perl with

NL> system(`awk '{print $10,$1}' statdata.dat `);

system 'awk \'{print $10,$1}\' statdata.dat';
system q{ awk '{print $10,$1}' statdata.dat };

of course you should also add the appropriate error
checking, see the system entry in the perlfunc(1)
manpage for how to do this.

NL> which should do the same. This time awk complains:

[ awk errors snipped ]

personally, I think you are going about it the wrong way, it
is trivial in Perl to open a file, and print out the 10th
and 1st columns for each record in the file.. so use Perl.

NL> I have tried escaping \' because i assumed that the ' of awk confuses perl
NL> but the problem remains. I also tried to escape $ in the awk command but
NL> again i got the same problem. Can someone please help. I am not a unix guru
NL> just an ordinary user. What am i missing here?

The fact that there is no need for awk for what you want to do.

:-)

anm

-- 
perl -wMstrict -e '
$a=[[qw[J u s t]],[qw[A n o t h e r]],[qw[P e r l]],[qw[H a c k e r]]];$.++
;$@=$#$a;$$=[reverse sort map$#$_=>@$a]->[$|];for$](--$...$$){for$}($|..$@)
{$$[$]][$}]=$a->[$}][$]]}}$,=$";$\=$/;print map defined()?$_:$,,@$_ for @$;
'


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

Date: Fri, 22 Dec 2000 18:37:45 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: problem with awk in perl script
Message-Id: <t477rpqoec17b5@corp.supernews.com>


Andrew makes a good point. However, he didn't point out
that the backtick isn't just a quote in Perl.

In comp.lang.perl.misc Andrew N. McGuire <anmcguire@ce.mediaone.net> wrote:
>>>>>> "NL" == Nikos Laoutaris <laoutaris@di.uoa.gr> writes:

> NL> system(`awk '{print $10,$1}' statdata.dat `);

Here you are calling system with the return value of
your awk program. This is similar to the following:

$call = `awk '{print $10,$1}' statdata.dat `;
system("$call");

You can verify this by running the two test programs
below:

############# prog1
system(`echo foo!`); # echos nothing

############# prog2
system(`echo echo foo!`); # echos 'foo!' because of the second echo



What the OP really wants to do (other than to use Perl without awk,
that's already been mentioned, may not be optimal in the OP's
situation, and sounds a bit elitist although accurate) is to either
use the backticks without system() or to use system() without the
backticks.

system('awk \'{print $10,$1}\' statdata.dat '); # this should work
`awk '{print $10,$1}' statdata.dat `; # this should work

The OP probably also wants to check / use the return values on such
calls.

$result = system('programtocall and arguments');
$result = `programtocall and arguments`;

Chris
--
Christopher E. Stith
mischief@motion.net



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

Date: Fri, 22 Dec 2000 16:33:43 GMT
From: Sportbike World <sportbikeworld@my-deja.com>
Subject: Re: regexp question
Message-Id: <91vvp7$eg2$1@nnrp1.deja.com>

Jerome,

This is Robert Basil (Sorry for the different posting address, but I am
at work)

I tried what you listed below but it did not work.

If I do s/\.{53}//sg; it will remove the 53 periods, but I need to
remove:

###Begin Example Message###

 .....................................................
remove this text
 .....................................................

keep this text

 .....................................................
remove this text
 .....................................................

###End Example Message###

Your idea below does not remove anything from the text file.

> Let's restate the problem this way (tell me if i'm wrong): you want to
> remove 2 blocks delimited with 53-period lines. Here is regexp which
> does it:
>
>     s/\.{53}.*?\.{53}//sg;
>
> Note that without the /s modifier, '.+' does not match through newline
> characters.
>
> Jerome.
>

---
Robert Basil
Chandler Unified School District


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 22 Dec 2000 16:44:17 GMT
From: Sportbike World <sportbikeworld@my-deja.com>
Subject: Re: regexp question
Message-Id: <9200cv$f1p$1@nnrp1.deja.com>

Gary,

Thanks for the help, I guess I should have stated that I am doing this
through a procmail script. And the file is not written to a text file
but read from memory. I'm not sure how I would invoke the perl script
below and point it to the incoming message.

i.e. In my procmail script all I have to do to run a regexp on an
incoming message is:

| perl -p -e 's/expressions/expressions/sg'

Robert Basil

In article <YOK06.854$Kk5.41665@eagle.america.net>,
  garry@zvolve.com wrote:
> On Fri, 22 Dec 2000 06:02:50 GMT, Robert Basil
> <robert@no-spam.basil.com> wrote:
> > Robert Basil wrote:
> > > So when I try and remove them, my regexp also removes the middle
> > > part of the message that I want to keep. I have triend about 20
> > > different regexp's with no luck so far. Any hints?
>
> [snip]
>
> >I want to remove Block A and C (which are exactly the same) and leave
> >B intact.
> >
> ><MULTILINE BLOCK OF TEXT A>
> ><MULTILINE BLOCK OF TEXT B>
> ><MULTILINE BLOCK OF TEXT C>
> >
> >Here is a copy of what is in the A and C blocks that I want to
> >remove: (Yes, the 4 lines of 53 periods need to be removed also)
>
> [snip]
>
> So your problem can be restated this way:
>
>     Remove all lines between lines of 53 periods inclusively.
>
> Here's a way to do it:
>
>     #!/usr/local/bin/perl
>     use strict;
>     use warnings;
>
>     my $state = 0;
>
>     while (<DATA>) {
>
>       # Printing lines state
>       $state == 0 and do {
> 	if ( /^\.{53}$/ ) {
> 	  $state = 1;
> 	  next;
> 	}
> 	print;
>       };
>
>       # Skipping lines state
>       $state == 1 and do {
> 	if ( /^\.{53}$/ ) {
> 	  $state = 0;
> 	  next;
> 	}
>       };
>     }
>
>     __DATA__
>
>     ####Begin Example Before Message####
>     .....................................................
>
>     SUBSCRIBE
>
>     Blah blah
>
>     .....................................................
>
>     The text that is here needs to be kept.
>
>     .....................................................
>
>     Blah blah
>
>     .....................................................
>     ####End Example Before Message####
>
>     ####Begin Example After Message####
>
>     The text that is here needs to be kept.
>
>     ####End Example After Message####
>
> This same approach is easily adapted to removing lines from an array
> of lines, if you insist on reading the entire file into an array.
>
> --
> Garry Williams
>

--
---
Sportbike World
FREE Email, Forums, Screensavers, Homepages.
Talk with THOUSANDS of other Sportbike Riders!
http://www.sportbikeworld.com


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 22 Dec 2000 18:51:18 +0100
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: regexp question
Message-Id: <nd074tom8iuo0b1d95vl8ht13fq0m4q2ab@4ax.com>

On Fri, 22 Dec 2000 06:02:50 GMT, "Robert Basil"
<robert@no-spam.basil.com> wrote:

> I want to remove Block A and C (which are exactly the same) and leave B
> intact.
> 
> <MULTILINE BLOCK OF TEXT A>
> <MULTILINE BLOCK OF TEXT B>
> <MULTILINE BLOCK OF TEXT C>
> 
> Here is a copy of what is in the A and C blocks that I want to remove: (Yes,
> the 4 lines of 53 periods need to be removed also)

 ... [ on to the example of <MULTILINE BLOCK OF TEXT A/C> ] 

> .....................................................
> 
> SUBSCRIBE
> 
> If this newsletter has been forwarded to you, and
> you wish to subscribe, simply send a blank e-mail to:
> mailto:subscribe-listname@domain.com
> 
> UNSUBSCRIBE
> 
> You are currently subscribed to mailing-list-name:
> listname@domain.com
> To unsubscribe send a blank email to
> mailto:leave-listname@domain.com
> .....................................................


This matches the dotted lines and _any_ text in between. The '.+?' bit
in the middle should be more specific, to allow for the message itself
to contain lines of 53 periods, but this has a nice sort symmetric look,
it almost reads like a palindrome :-)

	$msg =~ s/^\n?\.{53}\n.+?\n\.{53}\n?$//gsm;


-- 
Good luck,
Abe
perl -wle '$_=q@Just\@another\@Perl\@hacker@;print qq@\@{[split/\@/]}@'


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

Date: Fri, 22 Dec 2000 10:57:51 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: regular expr.
Message-Id: <slrn946ufv.7q9.tadmc@magna.metronet.com>

Dimitri Gunsing <somewhere@planet.earth> wrote:

>Use this one :
>$string =~ m/\[TITLE=(.*?)\]/;
>
>The ? means it should save the text until the next atom in the expression
>which is the closing ].


No it doesn't. Question mark is not related to "saving text",
parenthesis do that.

Question mark makes the .* non-greedy rather than greedy, but the
text will be saved with or without the question mark (though it
could be different characters that end up being saved).


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


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

Date: Fri, 22 Dec 2000 10:53:25 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Sorting hash
Message-Id: <slrn946u7l.7q9.tadmc@magna.metronet.com>

eggrock@my-deja.com <eggrock@my-deja.com> wrote:
>
>
>> You should instead do it as in the FAQ.
>
>And the FAQ says:


That is not the part that corresponds to the OP's question.

That part would be:

    @keys = sort {
                    $hash{$a} cmp $hash{$b}
            } keys %hash;       # and by value

where all that needs to be done is change the variable names
and the comparison operator.


>Read the description of 'sort' in the Programming Perl book (2nd ed.
>anyways)


I don't generally ask (or expect) folks to look at books. They are
not part of standard Perl, and so access cannot be assumed, as it
can be with references to the standard docs.

I do agree that many FAQ answers could be made more gentle. I've
often toyed with the idea of making a "small words" FAQ were the
answers have been reduced to a "lowest common denominator" level.
But I find it hard to become motivated to actually do such a thing...


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


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

Date: Fri, 22 Dec 2000 18:17:57 GMT
From: Jerome Abela <Jerome.Abela@free.fr>
Subject: Re: Splitting text, but not individual words
Message-Id: <3A439A0B.801BB1AF@free.fr>

Tad McClellan a écrit :
> Jerome Abela <Jerome.Abela@free.fr> wrote:
> >If you are not willing to use Text::Wrap, here is a single-line,
> >pattern-only
> >solution:
>  ^^^^^^^^
> >    s/(.{0,80})( |)/\1\n/g;
> 
> For some loose definition of "solution" I suppose.

I don't understand how I could have written this. It's probably a last
minute change after my tests (but what for ???), as my tmp dir only
shows tests with "s/(.{0,80}) /\1\n/g;". Maybe it was a hopeless attempt
to solve the case where no space is found for more than 80 characters.

> Code that generates warnings is always suspect as well.

What warning did you get ? Is it about \1/$1 ?

> ----------------------------------
> #!/usr/bin/perl -w
> [Example of usage for some code that never works. And it doesn't work, indeed]

Sorry about that.

Here are 2 better attempts:
    s/(.{0,80})\s+/$1\n/g;               # If there is no big word
    s/(?:(.{0,80})\s+|(.{80}))/$1$2\n/g; # also splits 80 char words


Jerome.


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

Date: Fri, 22 Dec 2000 17:18:58 +0100
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
Subject: Strange CGI.pm behaviour
Message-Id: <3A437EF2.8C84B624@eed.ericsson.se>

Hi,

     perl -M'CGI qw (:standard)' -e 'print hidden (-name  => "x", 
                                                   -value => param ("y"), 
                                                   -force => 1)'
prints:

    <INPUT TYPE="hidden" NAME="x" VALUE="-force">

But
     perl -M'CGI qw (:standard)' -e 'print hidden (-name  => "x", 
                                                   -value => undef, 
                                                   -force => 1)'
prints:

    <INPUT TYPE="hidden" NAME="x" VALUE="">

I am looking at the source code of the CGI.pm version 2.56
(included with Perl 5.6.0) on my Solaris 2.6 workstation and
don't understand yet, why? Does anyone have an idea?

Regards
Alex


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

Date: Fri, 22 Dec 2000 17:20:58 GMT
From: Terrence Brannon <brannon@lnc.usc.edu>
Subject: Re: Use PERL or Java? Which is faster?
Message-Id: <lbk88smky2.fsf@lnc.usc.edu>

Kenny Pearce <kenny@kennypearce.net> writes:

> actually, I just recently read the article at Perl.com on gtk+ programming in
> Perl. I didn't know until I read it that you could make GUIs in perl! now that I
> know this, I'm not sure I'll use Java for anything other than web applets.

But think about Perl/Tk instead of gtk+. More stable and what you
learn will allow you to use Tk on multiple programming languages.


-- 
Terrence Brannon
Carter's Compass...
    I know I'm on the right track when by deleting code I'm adding
    functionality.


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

Date: Fri, 22 Dec 2000 16:42:51 GMT
From: rzilavec@tcn.net (Richard Zilavec)
Subject: vec seems to need a tmp in my .pm file??
Message-Id: <3a447403.89454067@news.tcn.net>



I have a program that I want to convert into a package, everything
seems to be working except one method, which worked fine as a
subroutine.  

# this is the original
sub insert {

	my($num, $total) = @_;
	my(%hash, $bitstring);

	dbmopen(%hash, '/usr/database', oct("0600")) ||
		die "$!\n";

	unless(defined $hash{$num}) {
		$hash{$num} = pack("b*", "0" x $total);
	}
	vec($hash{$word}, $num, 1) = 1;
	# more stuff here

Well the above code is not totally complete but this is the part that
doesn't work in the package.  In the package I have to place
$hash{$word} into a temp value, use vec on the temp value and then
write it back to $hash{$word} or it never changes the bit. So it would
look like so in the package..

# this is in my package
	unless(defined $hash{$num}) {
		$bitstring = pack("b*", "0" x $total);
		vec($bitstring, $num, 1) = 1;
		$hash{$num} = $bitstring;
	} else {
		$bitstring = $hash{$num};
		vec($bitstring, $num, 1) = 1;
		$hash{$num} = $bitstring;
	}

This works fine in the package, I just can't figure out why the first
one is failing and I would rather not use a tmp it possible.

--
 Richard Zilavec
 rzilavec@tcn.net


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

Date: 22 Dec 2000 18:13:52 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Why are multiple zeroes true?
Message-Id: <slrn9476f0.95k.abigail@tsathoggua.rlyeh.net>

Bart Lateur (bart.lateur@skynet.be) wrote on MMDCLXX September MCMXCIII
in <URL:news:jhq64to4q0d9da44d86o9map1c95crs9hc@4ax.com>:
][ Abigail wrote:
][ 
][ >:} you are going backwards. starting with undef you can get to '', 0 and
][ >:} then to '0'. you cannot generate '00' from those with just context.
][ >
][ >You can't generate 0.0 from context either, yet that's false too.
][ 
][ Not so. "0.0" as a string is true, and 0.0 as a number is identical to
][ 0.

Well, 00 as a number is identical to 0 too, but '00' is true while '0'
is false. I don't see which point you are trying to make.



Abigail
-- 
perl -we '$_ = q ?4a75737420616e6f74686572205065726c204861636b65720as?;??;
          for (??;(??)x??;??)
              {??;s;(..)s?;qq ?print chr 0x$1 and \161 ss?;excess;??}'


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

Date: 22 Dec 2000 19:00:44 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Why are multiple zeroes true?
Message-Id: <9208cs$idr$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was sent to Abigail
<abigail@foad.org>],
who wrote in article <slrn9469fq.95k.abigail@tsathoggua.rlyeh.net>:
> You can't generate 0.0 from context either, yet that's false too.

Since the difference between 0 and 0.0 is detectable by XSUBs only,
you *can* generate 0.0.  Same for 0.000, 0.00e-3 etc (which have *no*
difference with 0.0).

> As you can see, to check for trueness, Perl prefers to check the
> string value of a scalar, then the integer value and then the double.
> It has to, to handle "0" vs "00" correctly.
> 
> But if multiple 0's would result in false, Perl can go for the (fast)
> integer check first, and only check the string if the scalar has 
> neither a valid integer nor a valid double value.

Yeah, right!

  $true = 'true';
  printf 'true=%d\n', $true;

Now you want $true to become false?  perldoc perlnumber for details.

The current semantic of trueness allowed the "sane numberics"
semantic.  [As a minimum, "sane" means no change of value via
read-only access.]  Thus *there is* at least ONE argument in favor of
the current semantic.  ;-)

Ilya


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

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


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