[25070] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7320 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 27 11:05:53 2004

Date: Wed, 27 Oct 2004 08:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 27 Oct 2004     Volume: 10 Number: 7320

Today's topics:
    Re: Common file operations <bik.mido@tiscalinet.it>
    Re: Common file operations <bik.mido@tiscalinet.it>
    Re: Common file operations (Seymour J.)
    Re: Compiling or Hiding Perl <peter@semantico.com>
    Re: Compiling or Hiding Perl <tadmc@augustmail.com>
    Re: Compiling or Hiding Perl <lwt0301@bellsouth.net>
    Re: Compiling or Hiding Perl <lwt0301@bellsouth.net>
    Re: Fast random string generation (Randal L. Schwartz)
    Re: Get Win32 Total Physical Memory & Available Physica <mirak63@carolina.rr.com>
    Re: help in parsing xml messages <tadmc@augustmail.com>
        HOW TO replace ' but not ?' <torfinnk@hotmail.com>
    Re: HOW TO replace ' but not ?' <peter@semantico.com>
    Re: HOW TO replace ' but not ?' <postmaster@localhost.localdomain>
    Re: HOW TO replace ' but not ?' <postmaster@localhost.localdomain>
    Re: HOW TO replace ' but not ?' <bernard.el-haginDODGE_THIS@lido-tech.net>
    Re: HOW TO replace ' but not ?' <tadmc@augustmail.com>
    Re: HOW TO replace ' but not ?' <mritty@gmail.com>
    Re: Linux vs. Windows: different behaviour [re rand()] <bik.mido@tiscalinet.it>
    Re: Linux vs. Windows: different behaviour [re rand()] <1usa@llenroc.ude.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 27 Oct 2004 16:34:15 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Common file operations
Message-Id: <stavn0pb8gd309fpdr9r7ggc48ggdv5qrg@4ax.com>

On 27 Oct 2004 04:00:37 GMT, "A. Sinan Unur"
<usa1@llenroc.ude.invalid> wrote:

>> Why should I bother for someone who already has made up her mind?
>
>Are you related to Arnold Schwarzenegger by any chance? I would read the 
>name of the person I am corresponding with a little more carefully if I 
>were you.

BTW: my (Italian, masculine) name, i.e. "Michele", is so often
mistaken in for the (French, feminine) "Michelle", that I'm by no
means bothered by this...


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Wed, 27 Oct 2004 16:34:16 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Common file operations
Message-Id: <31bvn0pnelmb5sgm3k5ds5ffcjavv4lfjn@4ax.com>

On Tue, 26 Oct 2004 19:37:05 -0300, "Shmuel (Seymour J.) Metz"
<spamtrap@library.lspace.org.invalid> wrote:

Unfortunately I can't help you with anything that is really OS/2
specific. Here are some hopefully constructive (i.e. that *you* will
hopefully judge to be constructive) cmts about your script in any
case:

> extproc G:\emx\bin\perl -STw
> #!/usr/bin/perl -Tw

BTW: do you really need -T? I suppose this is to be run from the
cmd/line and AFAICT doesnt' support risky operations, but I may be
wrong...

Also, with modern perls it's better to

  use warnings;

instead. And

  use strict;

*always*. (Well, but for one-liners, golfing, JAPHs, etc.)

> use constant TRUE  => 1;
> use constant FALSE => '';

Huh?!? Don't do this! Well, if you really really like... then do it,
but in Perl it's not recommendable in any case. And certainly not
useful...

> #ARGV=('m*','xyz');
> my ($dir,$file)=@ARGV;

Hmmm, then I'd rather do (somthing like):

  @ARGV == 2 or die "Usage: $0 <wildcard> <file>\n";

> print '@ARGV=(',join(',',@ARGV),")\n";
> print '$dir =',"$dir\n";

Not a real issue, but are you sure you want to print all these info?
In particular $dir and $file before and after the transformation...

> $dir  =~ s/^\'?([^\']*)\'?$/$1/;

Hey, and you said you had never heard about regexen...

However... you're just removing possible C<'>s from at ^ or $, right?
Then I suggest you do something like

  s/^'//, s/'$// for $dir;

which is clearer IMHO...

> print '$dir =',"$dir\n";
> print '$file=',"$file\n";
> $file =~ s/^\'?([^\']*)\'?$/$1/;

Oh, this one too, then why not doing them both in one run? A la

  s/^'//, s/'$// for $dir, $name;

Also, still if you really *do* want to print all those info, then for
clarity resons you may consider an HERE doc instead.

> print '$file=',"$file\n";
> my @dirs=glob($dir);
> print '@dirs=(',join(',',@dirs),")\n";
> unless (scalar(@dirs) == 1) {
          ^^^^^^
          ^^^^^^

This is not required

>    print "$dir matches multiple directory names:\n";
>    die '  ', join("\n  ",@dirs),"\n"
>    }
> die "$dir is an invalid directory name.\n" unless -d $dir;

You may have used

  @dirs=grep -d, glob $dir;

in the first place.

>>What is a file specification in your terminlogoy?
>
>I'd probably want to support the OS/2 conventions, which use * and ?
>as wildcards, with ? matching a single component. I haven't decided

This is the convention on *NIX and DOS/Win too. Apart that *NIX shells
support other ones as well.

>[2] OS/2 uses \ as a separator rather than /.

Well, I don't know OS/2, and so I cannot tell about Perl under OS/2,
but under DOS/Windows the directory separator is \ too, however Perl
lets you use / anyway. I *guess* that it may be the same for OS/2.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Wed, 27 Oct 2004 08:26:03 -0300
From: "Shmuel (Seymour J.) Metz" <spamtrap@library.lspace.org.invalid>
Subject: Re: Common file operations
Message-Id: <417f93db$1$fuzhry+tra$mr2ice@news.patriot.net>

(2nd response)

In <251020041625004613%jgibson@mail.arc.nasa.gov>, on 10/25/2004
   at 04:25 PM, Jim Gibson <jgibson@mail.arc.nasa.gov> said:

>What computer language allows you to enter a partial file name and
>get a complete path?

REXX.

It turns out that Cwd::abs_path will do the job in Perl, although the
implimentation is ugly.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org



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

Date: Wed, 27 Oct 2004 14:24:03 +0100
From: Peter Hickman <peter@semantico.com>
Subject: Re: Compiling or Hiding Perl
Message-Id: <417fa174$0$2390$afc38c87@news.easynet.co.uk>

Right I asked this on the perl6-internals and it would seem that compiling Perl 
6 source to parrot bytecode and than loading the bytecode instead of the source 
was doable, with some possible caveats.

Here's the message:

Dan Sugalski wrote:

 > At 12:00 PM +0100 10/27/04, Peter Hickman wrote:
 >
 >> Presently Python compiles it's py files to pyc files that can then be run 
without access to the source (the py).
 >>
 >> Would Perl 6 be able to do this? Compile the pl to plc and pm to pmc and 
load the ??c version if it was available and newer than the source?
 >
 > Yeah, that's doable. Probably will be done.
 >
 >> Other than code hiding would there be any performance benefits?
 >
 > Given that the bytecode will probably have a segment with the original source 
in it, this isn't likely to get you much of a win there.
 >
 > There should be a performance win, though. There won't be a need to compile 
the source, which saves some time. Bytecode files on-disk are shared across all 
the processes in the system, so you only get one in-memory copy of a file, which 
saves both RAM and load time if you're using a file that another process is using.
 >
 > On single user or small machines this probably won't be a big win in most 
cases. It should, however, make a pretty big difference in server systems.
 > --
 >                 Dan
 >
 > --------------------------------------it's like this-------------------
 > Dan Sugalski                          even samurai
 > dan@sidhe.org                         have teddy bears and even
 >                                       teddy bears get drunk

So probably yes, but we will have to wait and see what it looks like.


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

Date: Wed, 27 Oct 2004 07:35:25 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Compiling or Hiding Perl
Message-Id: <slrncnv5gd.q1r.tadmc@magna.augustmail.com>

daniel kaplan <nospam@nospam.com> wrote:

> you either goose-step
> to the fuehrer...i mean FAQ, or you are wrong...


What daniel calls "goose-stepping" most other folks would 
call "good manners".

You either practice good manners...I mean check the FAQ before posting,
or you are wrong.


   In article <1995Nov9.193745.13694@netlabs.com>, lwall@netlabs.com 
   (Larry Wall) wrote: ...

    [snip]  I view a programming language as a place to be
    explored, like Disneyland. You don't need to have a lot of preparation
    to explore a theme park.  You do have to go along with the crowd
    control measures, though.  In a sense, each ride has its own
    prerequisites--if you cut in line, you risk getting tossed out of the
    park.
   
    What we have here in this newsgroup is a failure in crowd control.
    Reading the FAQ is like staying in line--it's something you should
    learn in kindergarten.  Usenet needs a better kindergarten.


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


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

Date: Wed, 27 Oct 2004 10:25:02 -0400
From: Laura <lwt0301@bellsouth.net>
Subject: Re: Compiling or Hiding Perl
Message-Id: <10nvc4is88hqfac@news.supernews.com>

daniel kaplan wrote:

>> Read it again. (specifically the fourth paragraph of the first FAQ you
>> mentioned).  The answer is not "Not today".  The answer is "That's the
>> wrong method".
> 
> well i read it as "not today" because someone does seem to be working on
> one in the experimental stage.
> 
>> No, because hiding or obfuscating source code is not the correct way to
>> protect your company's IP.  The way to do that is with proper
>> trademarks, copyrights, and patents.
> 
> it is however the first step in a very complicated steps of defense.  i've
> written three software patents, and as you may know they take years to
> approve and cost money to file, and cost money to defend.  and by defend i
> meant answering back when the PTO comes back with their first rejection.
> which they almost always do.
> 


The nature of the Perl culture is to be open in sharing source code as is
the nature of the much of the open source community.  To understand the
nature of differing software communities, you must follow the money trail
because nobody does this much hard work for free no matter how much they
love it.  Microsoft and Apple and like minded corporations attempt to make
software that is easy to use but difficult to hack into.  They make their
money selling software, but they lose money on the support end when the
support is included in the price of the software and they lose money on
copyright infringement.  Therefore, they protect their investment with all
possible resources, particularly compilation and obfuscation of code.  The
open source community makes its money on support and service of freely
distributed code.  It is no accident that products like Linux, Perl and
others are free, yet so difficult for the beginner to learn and use. 
Whether it is conscious or unconscious, the programmers of free software
build into their work an innate difficulty for the absolute novice.  Of
course, code is well organized and occasionally well documented as a matter
of pride, but little effort is made to make it accessible to the beginner
or even the user who wants to use the software without dedicating a
substantial amount of time to becoming a "hacker".  Again, follow the money
trail.  Do a survey of how often you read the response "hire a programmer." 
There is nothing wrong with this philosophy.  Why should programmers invest
so much time, money and effort into their own education and work and then
give it away for free?  Unless of course the person asking for help shows
some desire to become a programmer themselves by putting a little work and
effort in before asking their question.  It makes sense to give a little
free help to this person in the hopes that someday, they may evolve into a
competent hacker who will contribute something useful for the community.

Just see that "Antitrust" movie to get a better understanding of the issue.


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

Date: Wed, 27 Oct 2004 10:45:10 -0400
From: Laura <lwt0301@bellsouth.net>
Subject: Re: Compiling or Hiding Perl
Message-Id: <10nvd9q7ss5j660@news.supernews.com>

TOP POSTER!

Reason for not top posting:

They have not yet written a decent Perl filter to turn top posting into
bottom posting as your post is submitted.  If anyone figures out how to do
it and puts it on cpan, we could all use it on the client side for now to
fix top posts as they come in.

Samik Raychaudhuri wrote:

> Check the section titled 'Using bytecode and the compiler back ends' at
> the following link:
> http://www-106.ibm.com/developerworks/library/l-optperl.html?ca=dgr-lnxw0
> This is actually from one of the recent posts titled 'Optimize Perl..'.
> Thanks OP. HTH. -Samik
> 
> On 10/26/2004 1:01 PM, daniel kaplan wrote:
>>>Read it again. (specifically the fourth paragraph of the first FAQ you
>>>mentioned).  The answer is not "Not today".  The answer is "That's the
>>>wrong method".
>> 
>> 
>> well i read it as "not today" because someone does seem to be working on
>> one in the experimental stage.
>> 
>> 
>>>No, because hiding or obfuscating source code is not the correct way to
>>>protect your company's IP.  The way to do that is with proper
>>>trademarks, copyrights, and patents.
>> 
>> 
>> it is however the first step in a very complicated steps of defense. 
>> i've written three software patents, and as you may know they take years
>> to
>> approve and cost money to file, and cost money to defend.  and by defend
>> i meant answering back when the PTO comes back with their first
>> rejection. which they almost always do.
>> 
>> the great thing about software is that you and  i as a two man company
>> could
>> come up with the next killer app, and launch with not much money.  and
>> yes,
>> the first defense is, don't let them see your code.  of course you MUST
>> follow it up with patents, and the likes, as you described above and in
>> the FAQ.
>> 
>> since you didn't mention it in your reply, i take it however, that there
>> is
>> no such beast forthcoming that anyone knows about.  which sorta sucks
>> because while many "sensitive" firms (Nasa, Gruman, and the likes) will
>> only run software on their "internal" networks, these are the last
>> companies that behave improperly.
>> 
>> but there are those mid-companies who want it internally, but you just
>> never know who is working there and what might happen....
>> 
>> thanks
>> 
>> 
> 



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

Date: 24 Oct 2004 08:00:46 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Fast random string generation
Message-Id: <86oeis40v5.fsf@blue.stonehenge.com>

>>>>> "Peter" == Peter J Acklam <pjacklam@online.no> writes:

Peter> Derek Fountain <nospam@example.com> wrote:
>> I need to generate a string of random characters, say about
>> 20,000 characters long. And I need to do it quickly! I tried the
>> obvious:
>> 
>> for( my $i=0; $i<20000; $i++ ) {
>> $str .= chr(int(rand(256)));
>> }
>> 
>> which works, but I have a feeling there must be a faster way
>> than doing 20,000 string concatenations...?

Peter>     my $str = "\000" x 20_000;
Peter>     my @chr = map { chr $_ } 0 .. 255;
Peter>     substr $str, $_, 1, $chr[rand 256] for 1 .. 20_000;

maybe:

        pack "C*", map rand 256 for 1 .. 20_000;

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Wed, 27 Oct 2004 10:37:44 -0400
From: "KWall" <mirak63@carolina.rr.com>
Subject: Re: Get Win32 Total Physical Memory & Available Physical Memory stats
Message-Id: <bf6dnX1pQNQmL-LcRVn-3Q@giganews.com>


"ko" <kuujinbo@hotmail.com> wrote in message 
news:2u9g2sF27lsdpU1@uni-berlin.de...
> Karim Wall wrote:
>> Hello. I've checked CPAN and have searched the net as well and have not 
>> been able to find a Perl script or module that will get me the Total 
>> Physical Memory and Available Physical Memory stats for a remote system, 
>> much less an NT utility. The one utility I found, SYSTEMINFO.EXE can't be 
>> used to get info on an NT4 system and I have plenty of them.  I've found 
>> some scripts that provide task mgr types of info but that's too much.
>>
>> Any ideas?
>>
>> Thanks,
>> Karim
>
> Try Perl's Win32::OLE and MS's WMI:
>
> use strict;
> use warnings;
> use Win32::OLE qw[in];
>
> my $host  = $ARGV[0] || '.';
> my $wmi   = Win32::OLE->GetObject( "winmgmts://$host/root/cimv2" )
>             or die Win32::FormatMessage( Win32::OLE::LastError() );
>
> my %instances = (
>   Win32_PhysicalMemory  => \&get_pmem,
>   Win32_PerfRawData_PerfOS_Memory => \&get_amem,
> );
>
> my $out;
> foreach ( keys %instances ) {
>   my $class = $wmi->InstancesOf( $_ );
>   $out .= $instances{ $_ }->( $class );
> }
> print $out;
>
> sub get_pmem {
>   my $class = shift;
>   my $total;
>   $total +=  $_->{Capacity} foreach in($class);
>   return "Physical Memory: $total\n";
> }
>
> sub get_amem {
>   my $class = shift;
>   my $amem;
>   $amem .= join ' ', $_->{AvailableBytes} foreach in($class);
>   return "Available Memory: $amem\n";
> }
>
>
> Good resources:
>
> Basics of using Win32:OLE & WMI:
> http://www.ntmag.com/WindowsScripting/Article/ArticleID/19828/19828.html
>
> WMI Win32 clases:
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_classes.asp
>
> HTH - keith

I noticed "my $host  = $ARGV[0]". I assumed that this was a target remote 
server. However, I get  "Too many parameters" error when I run SCRIPT.PL 
SERVERNAME. Is this what you intended?
Thanks,
Karim 




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

Date: Wed, 27 Oct 2004 08:26:07 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: help in parsing xml messages
Message-Id: <slrncnv8ff.q1r.tadmc@magna.augustmail.com>

Julie <nagoba@rediffmail.com> wrote:

> I have an xml string like so.....


[ snip data, repeated in code below ]


> I want to parse it so that I can then 
> create a query via
> reading the innermost loop and then the outer loop and then the outer loop,


> how do I parse the xml to do this ?


By using XML::Simple, references and a recursive traversal of 
the data structure that it returns:

-------------------------------
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
use XML::Simple;

my $xml_ref = XMLin <<'ENDXML';
<q path="bugs/bug/bugs/@bug_id=3" match="endswith" true="true" op="and">
  <q path="bugs/bug/reports/@id=57" match="binary" true="true" op="and">
    <q path="bugs/bug/reports/@id=21" match="partial" true="true" op="or"/>
  </q>
</q>
ENDXML

# print Dumper $xml_ref;   # for debugging

my @paths;
params( $xml_ref, \@paths );
print "$_\n" for @paths;

sub params {
   my( $xml, $paths_ref ) = @_;

   if ( exists $xml->{q} ) {
      params( $xml->{q}, $paths_ref );
   }

   if ( exists $xml->{path} ) {
      push @$paths_ref,  $xml->{path};
   }
}
-------------------------------


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


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

Date: Wed, 27 Oct 2004 15:30:23 +0200
From: "tor" <torfinnk@hotmail.com>
Subject: HOW TO replace ' but not ?'
Message-Id: <417fa2f1$0$237$edfadb0f@dread11.news.tele.dk>

Hello
I want to put a new line after each ', but not after ?'.
If someone are familiare with edifact they understand.

AAA+Tim?'s'BBB+123'

should become

AAA+Tim?'s'
BBB+123'

anyone???

Torfinn




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

Date: Wed, 27 Oct 2004 14:44:07 +0100
From: Peter Hickman <peter@semantico.com>
Subject: Re: HOW TO replace ' but not ?'
Message-Id: <417fa628$0$505$afc38c87@news.easynet.co.uk>

tor wrote:
> Hello
> I want to put a new line after each ', but not after ?'.
> If someone are familiare with edifact they understand.
> 
> AAA+Tim?'s'BBB+123'
> 
> should become
> 
> AAA+Tim?'s'
> BBB+123'
> 
> anyone???
> 
> Torfinn
> 
> 

How about this?

$a = "AAA+Tim?'s'BBB+123'";

print "$a\n";

$a =~ s/([^\?]')/$1\n/g;

print "$a\n";

The ([^\?]') says match and capture any character other than a ? that is 
followed by a '

The $1\n says replace this with whatever you captured plus a newline


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

Date: Wed, 27 Oct 2004 14:43:24 +0100
From: bengee <postmaster@localhost.localdomain>
Subject: Re: HOW TO replace ' but not ?'
Message-Id: <417fa5d7$0$55673$ed2619ec@ptn-nntp-reader02.plus.net>

tor wrote:
> Hello
> I want to put a new line after each ', but not after ?'.
> If someone are familiare with edifact they understand.
> 
> AAA+Tim?'s'BBB+123'
> 
> should become
> 
> AAA+Tim?'s'
> BBB+123'

Hi Tom. Done a bit of EDIFACT in my time! You need to use a regexp to 
replace "[not a question mark]'" so try this :-

my $var = "AAA+Tim?'s'BBB+123'";
print("BEFORE: $var\n");
$var =~ s/([^\?]\')/$1\n/g;
print("AFTER : $var\n");

HTH

Ben


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

Date: Wed, 27 Oct 2004 14:49:57 +0100
From: bengee <postmaster@localhost.localdomain>
Subject: Re: HOW TO replace ' but not ?'
Message-Id: <417fa760$0$55673$ed2619ec@ptn-nntp-reader02.plus.net>

bengee wrote:
> Hi Tom. Done a bit of EDIFACT in my time! You need to use a regexp to 
> replace "[not a question mark]'" so try this :-
> 
> my $var = "AAA+Tim?'s'BBB+123'";
> print("BEFORE: $var\n");
> $var =~ s/([^\?]\')/$1\n/g;
> print("AFTER : $var\n");

IIRC is the escape char in EDIFACT and to get a ? you need to escape 
itself, i.e. ?? So what about this :-

AAA+Tim OK??'s'BBB+123'

I'll leave you to work that one out as an exercise ;-)

bengee


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

Date: Wed, 27 Oct 2004 15:50:32 +0200
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: HOW TO replace ' but not ?'
Message-Id: <Xns958FA127E4ED4elhber1lidotechnet@62.89.127.66>

"tor" <torfinnk@hotmail.com> wrote:

> Hello
> I want to put a new line after each ', but not after ?'.
> If someone are familiare with edifact they understand.
> 
> AAA+Tim?'s'BBB+123'
> 
> should become
> 
> AAA+Tim?'s'
> BBB+123'


s/(?<!\?)'/'\n/g;


-- 
Cheers,
Bernard


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

Date: Wed, 27 Oct 2004 09:05:10 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: HOW TO replace ' but not ?'
Message-Id: <slrncnvaom.qbm.tadmc@magna.augustmail.com>

tor <torfinnk@hotmail.com> wrote:

> I want to put a new line after each ', but not after ?'.


> AAA+Tim?'s'BBB+123'
> 
> should become
> 
> AAA+Tim?'s'
> BBB+123'
> 
> anyone???


   s/(?<!\?)'/'\n/g;

or more readably:

   s/(?<! \? )       # preceding char is not a question mark
     '
    /'\n/gx;


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


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

Date: Wed, 27 Oct 2004 14:10:09 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: HOW TO replace ' but not ?'
Message-Id: <5%Nfd.2389$803.36@trndny04>

"Peter Hickman" <peter@semantico.com> wrote in message
news:417fa628$0$505$afc38c87@news.easynet.co.uk...
> tor wrote:
> > Hello
> > I want to put a new line after each ', but not after ?'.
> > If someone are familiare with edifact they understand.
>
> How about this?
>
> $a = "AAA+Tim?'s'BBB+123'";
> print "$a\n";
> $a =~ s/([^\?]')/$1\n/g;

Question marks are not special in character classes.  No need for a
backslash there.

> print "$a\n";
>
> The ([^\?]') says match and capture any character other than a ? that
is
> followed by a '
>
> The $1\n says replace this with whatever you captured plus a newline

I'm not familiar with EDIFACT, so this may not apply.  However, if there
is a possibility that a ' could be the first (or only) character in the
string, and you need to insert a newline after it, this will not work.
The [^?] requires an actual character.

To match just "an apostrophe not preceded by a question mark" (rather
than "anything that's not a question mark, followed by an apostrophe"),
you need to use negative lookbehind assertions:

s/(?<!\?)'/'\n/;

Paul Lalli




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

Date: Wed, 27 Oct 2004 16:34:17 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Linux vs. Windows: different behaviour [re rand()]
Message-Id: <40cvn0lo87cilg13t9v2tvmo3479aeert1@4ax.com>

On 26 Oct 2004 22:34:12 GMT, "A. Sinan Unur"
<1usa@llenroc.ude.invalid> wrote:

>> # perl -le '$,="\t"; print unpack "C*", pack "L", rand 2**32 for
>> 1..15'
>
>I am not sufficiently at ease with pack to see if something is wrong 
>above.

Neither am I, in the sense that I always have to check the docs, which
OTOH are clear enough. Well, at least for qw/C L/ I'm quite sure
nothing is consistently *wrong*.

>> Does the cmt at the end of 'perldoc -f rand' apply? Note: 5.8.4 in
>> both cases (AS under Windows).
>
>Same version here. You got me curious. I have:
>
>C:\Home> perl -MConfig -e"print qq{$Config{randbits}}
>15

Me too! (verified with 'perl -V:randbits', as suggested by another
poster.) And 48 under Linux.

>Dunno what you are observing but I don't think the bit about
>
>   If your rand function consistently returns numbers that
>   are too large or too small,
>
>applies here.

Definitely I *think* it does, in fact, with referral to my other post:

| C:\TEMP>perl -le "$,=qq|\t|; print unpack 'C*', pack 'L', rand 2**32 for 1..15"
| 0       0       246     13
| 0       0       174     202
| 0       0       104     241
| 0       0       116     246
| 0       0       10      76
| 0       0       4       44
| 0       0       64      61
| 0       0       244     123
| 0       0       252     86
| 0       0       78      181
| 0       0       124     45
| 0       0       100     103
| 0       0       188     62
| 0       0       100     100
| 0       0       196     191

The high order bytes are always 0, and the third column values are
always even (of course this is *not* an artifact of the limited sample
- check for yourself!)


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 27 Oct 2004 14:59:19 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Linux vs. Windows: different behaviour [re rand()]
Message-Id: <Xns958F6FC8246EFasu1cornelledu@132.236.56.8>

Michele Dondi <bik.mido@tiscalinet.it> wrote in
news:40cvn0lo87cilg13t9v2tvmo3479aeert1@4ax.com: 

> On 26 Oct 2004 22:34:12 GMT, "A. Sinan Unur"
> <1usa@llenroc.ude.invalid> wrote:
> 
>>> # perl -le '$,="\t"; print unpack "C*", pack "L", rand 2**32 for
>>> 1..15'
>>
>>I am not sufficiently at ease with pack to see if something is wrong 
>>above.
> 
 ...

> Definitely I *think* it does, in fact, with referral to my other post:
> 
>| C:\TEMP>perl -le "$,=qq|\t|; print unpack 'C*', pack 'L', rand 2**32
>| for 1..15" 0       0       246     13
>| 0       0       174     202

 ...
 
> The high order bytes are always 0, and the third column values are
> always even (of course this is *not* an artifact of the limited sample
> - check for yourself!)

OK, so I did this:

printf "%8.8X\n", int rand(2**32) for 1 .. 10_000;

First with AS Perl:

C:\Home> perl -v

This is perl, v5.8.4 built for MSWin32-x86-multi-thread

Here is some representative output:

6F860000 EBF20000 0E140000 28600000 02C00000 75B00000
1D140000 93260000 25960000 643C0000 CACA0000 A2800000
20980000 A0820000 94860000 B61A0000 CDE40000 ...

On the other hand,

asu1@host ~
$ perl -v

This is perl, v5.8.5 built for cygwin-thread-multi-64int

And here is some output in that case as well:

8758274B 80717716 BBCCB917 26622DE8 05D10A8A 84B2174B 
1BA68432 4F146432 59605227 88D18BA6 498D9C48 788227AD
F0892E9E 9FB09C8D D2E53F9F C56B388E 0D6A6B5D 0E8CCAA1
DF68A5F0 41E118A0 ...

I would say you are right.

So, would you like to file a bug report with ActiveState :)

Sinan.


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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