[23925] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6126 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 12 21:05:38 2004

Date: Thu, 12 Feb 2004 18: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)

Perl-Users Digest           Thu, 12 Feb 2004     Volume: 10 Number: 6126

Today's topics:
    Re: [SpreadSheet::ParseExcel] How to get the Cell comme <pkrupa@redwood.rsc.raytheon.com>
    Re: Alternative to Export for constants (Anno Siegel)
    Re: Alternative to Export for constants <kj345@lycos.com>
        Changing Mcdonald to McDonald <porter970@lycos.com>
    Re: Changing Mcdonald to McDonald <usenet@morrow.me.uk>
    Re: Changing Mcdonald to McDonald <gnari@simnet.is>
    Re: Changing Mcdonald to McDonald <matthew.garrish@sympatico.ca>
    Re: dereferencing problems <gnari@simnet.is>
    Re: Include data in a perl program? <usenet@morrow.me.uk>
        One more running Perl as a service question (Cosmic Cruizer)
    Re: parsing out all data between two words with multipl <gnari@simnet.is>
    Re: Perl Sockets Parent/Child Problem <tadmc@augustmail.com>
        PERL-SQL and date comparison <rafalk@comcast.net>
    Re: PERL-SQL and date comparison <usenet@morrow.me.uk>
    Re: PERL-SQL and date comparison <nospam@bigpond.com>
    Re: PERL-SQL and date comparison <rafalk@comcast.net>
    Re: PERL-SQL and date comparison <rafalk@comcast.net>
    Re: PERL-SQL and date comparison <gnari@simnet.is>
        Problem opening sed pipe (freewilly3d)
    Re: Problem opening sed pipe <uri@stemsystems.com>
    Re: Regular Expression Help Needed <krahnj@acm.org>
        Replacing hundreds of hash keys with their values in a  <apollock11@hotmail.com>
    Re: Replacing hundreds of hash keys with their values i <usenet@morrow.me.uk>
    Re: Replacing unicode characters <usenet@morrow.me.uk>
    Re: tying hashes (Anno Siegel)
    Re: tying hashes <yshtil@cisco.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 12 Feb 2004 23:40:50 +0000
From: "Peter A. Krupa" <pkrupa@redwood.rsc.raytheon.com>
Subject: Re: [SpreadSheet::ParseExcel] How to get the Cell comment
Message-Id: <77UWb.11$Uj6.0@dfw-service2.ext.ray.com>

Spreadsheet::ParseExcel does not appear to support the cell comment 
field.  The package documentation doesn't mention it, but just to be 
sure I used Data::Dumper to examine a worksheet object and the cell 
comment is nowhere to be found.  If you're feeling brave you could hack 
the package to support it.  :-(



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

Date: 12 Feb 2004 23:08:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Alternative to Export for constants
Message-Id: <c0h127$kl8$1@mamenchi.zrz.TU-Berlin.DE>

Ben Morrow  <usenet@morrow.me.uk> wrote in comp.lang.perl.misc:
> 
> kj <kj345@lycos.com> wrote:
> > 
> > One thing that bugs me about the Export module is that even when
>                                         ^^ er
> > you want the module to export everything, one still has to register
> > things in @EXPORT.  I find it particularly annoying in cases when
> > I have a module that contains only constants to be shared by other
> > modules and scripts, like this:
> > 
> > # file My_Constants.pm
> > package My_Constants;
> > use base 'Exporter';
> > our @EXPORT = qw(FOO BAR ... );
> > use constant FOO => 1;
> > use constant BAR => 4;
> > # etc.
> > 1;
> <snip>
> > # file My_Constants.pm
> > package My_Constants;
> > use constant FOO => 1;
> > use constant BAR => 4;
> > # etc.
> > 1;
> > 
> > # file some_script.pl
> > use My_Constants;
> > 
> > our $Const = bless \{ my $c }, 'My_Constants';
> > 
> > printf "%d %d\n", $Const->FOO, $Const->BAR;
> >
> > It works, though I've never thing anything like this done.  Is
> > there anything particularly wrong with it?
> 
> You won't get constant inlining, and the interface is messy (do you
> really want to have to do that 'bless' every time you use the module?)

The "bless" is a red herring.  Instead of generating an irrelevant object
to call the constant through, it can be called directly as a class method:

    My_Constants->FOO;

It's clearly not quite clean.  The constant will be called with an argument,
(class or object, either way), which its prototype actually forbids.  It
only works because prototypes are ignored in method calls.  Further, there
is no advantage in the class method call over the fully qualified
"My_Constants::FOO".  If inheritance is intended, I'd urgently recommend
not using constants but writing standard methods.

[snip good exporting alternative]

Anno


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

Date: Thu, 12 Feb 2004 21:10:52 +0000 (UTC)
From: kj <kj345@lycos.com>
Subject: Re: Alternative to Export for constants
Message-Id: <c0gq4s$r1a$2@reader2.panix.com>

In <c0gh7u$g59$1@wisteria.csv.warwick.ac.uk> Ben Morrow <usenet@morrow.me.uk> writes:

>Ben Morrow <usenet@morrow.me.uk> wrote:
>> kj <kj345@lycos.com> wrote:
>> >
>> > our $Const = bless \{ my $c }, 'My_Constants';
>> > 
>> > printf "%d %d\n", $Const->FOO, $Const->BAR;
>> >
>> > It works, though I've never thing anything like this done.  Is
>> > there anything particularly wrong with it?

>Another, stronger, objection is that this comes under the heading
>'using the symbol table when you could use an ordinary hash' (method
>calls are, essentially, symrefs).

>package My_Constant;

>use base      qw/Exporter/;
>our @EXPORT = qw/%Consts/;

>out %Consts = (
>    FOO => 1,
>    BAR => 2,
>);

>1;

>package main;

>use My_Constant;

>print $Const{FOO}, $Const{BAR};




Doh!

Thanks.

kj



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

Date: Thu, 12 Feb 2004 17:46:59 -0600
From: "porter970" <porter970@lycos.com>
Subject: Changing Mcdonald to McDonald
Message-Id: <102o43phggao63a@corp.supernews.com>

I have a form that requires people to enter their name.  Since many people
insist on typing in all caps, I first convert the last name to all small
letters using:

    $name =~tr/A-Z/a-z/;

I then capitalize the name using:

    $name =~ s/\b(\w)/\U$1/g;

(which I copied from somewhere and don't fully understand.)

Problem is, names like McDonald need the third letter capitalized.

Though trial and error I've come up with this

    if ($name =~ /^Mc[a-z]/i) {
          $name =~ s/^Mc([a-z])?/Mc\U$1/;
    }

Is there a cleaner/easier way?  Are there any glaring problems with this?

Thanks,
Steve




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

Date: Fri, 13 Feb 2004 00:05:13 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Changing Mcdonald to McDonald
Message-Id: <c0h4bp$h7$1@wisteria.csv.warwick.ac.uk>


"porter970" <porter970@lycos.com> wrote:
> I have a form that requires people to enter their name.  Since many people
> insist on typing in all caps, I first convert the last name to all small
> letters using:
> 
>     $name =~tr/A-Z/a-z/;
> 
> I then capitalize the name using:
> 
>     $name =~ s/\b(\w)/\U$1/g;
> 
> (which I copied from somewhere and don't fully understand.)

A simpler way to do it is
    $name = ucfirst($name);

> Problem is, names like McDonald need the third letter capitalized.
> 
> Though trial and error I've come up with this
> 
>     if ($name =~ /^Mc[a-z]/i) {
>           $name =~ s/^Mc([a-z])?/Mc\U$1/;
>     }
> 
> Is there a cleaner/easier way?  

Well... for what you're trying to do,
    $name =~ s/(?<=^Mc)([[:lower:]])/\U$1/;
I would consider neater.

A much easier way is to get people to enter their names right in the
first place.

> Are there any glaring problems with this?

The problem is essentially insoluble: by uppercasing their names,
people lose information. There is no way for you to get this info
back: for instance, consider the case of an inital 'de'. IIRC, some
people spell it DeFoo and some deFoo (and, indeed, some people are
called 'Dean' which looks *very* weird as 'DeAn' :)... you have no way
of knowing which is correct.

What I would do is, after they've entered the name, *if* it was all
caps (if ($name !~ /[[:lower:]]/) {), ucfirst it; then present them
with a second form with the new version in and a button saying 'please
press to confirm'. I reckon that if it's capitalised wrongly there
people'll correct it; if they don't, it's their problem and not yours
if you get it wrong.

Ben

-- 
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
   From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes,        [ Heracles shoots Vulture with arrow. Vulture bursts into ]
 /Alcestis/)        [ flame, and falls out of sight. ]         ben@morrow.me.uk


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

Date: Fri, 13 Feb 2004 00:12:51 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Changing Mcdonald to McDonald
Message-Id: <c0h4ob$3pj$1@news.simnet.is>

"porter970" <porter970@lycos.com> wrote in message
news:102o43phggao63a@corp.supernews.com...
> I have a form that requires people to enter their name.  Since many people
> insist on typing in all caps, I first convert the last name to all small
> letters using:
>
[snipped sheme that assumes McX is the only name with special
 capitalisation to exist]

> Is there a cleaner/easier way?  Are there any glaring problems with this?

why not assume that people capitalize their own name the way
they want it capitalized?

at least, limit your fiddling to cases the the name is all capitals, and
assume mixed capitals is correct.

gnari






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

Date: Thu, 12 Feb 2004 20:33:58 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Changing Mcdonald to McDonald
Message-Id: <9QVWb.9754$lK.649865@news20.bellglobal.com>


"porter970" <porter970@lycos.com> wrote in message
news:102o43phggao63a@corp.supernews.com...
> I have a form that requires people to enter their name.  Since many people
> insist on typing in all caps, I first convert the last name to all small
> letters using:
>
<snip corrective regexes>
>
> Is there a cleaner/easier way?
>

Yes, it's called client-side validation. Use a javascript to check the input
field doesn't contain all upper-case letters before allowing the form to be
submitted. And to be doubly sure, check in your script that the field is not
all-caps (or all lower-case), and barf an error if it is. e.e. cummings
won't like you, but then again he's dead.... : )

Matt




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

Date: Thu, 12 Feb 2004 22:52:56 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: dereferencing problems
Message-Id: <c0h02i$33v$1@news.simnet.is>

"Marshall Dudley" <mdudley@execonn.com> wrote in message
news:402BE6D0.70BE7337@execonn.com
> @fields = ("name","address","phone","\$date");
> or
> @fields = ("name","address","phone",'$date');
> or
> @fields = ("name","address","phone",'\$date');

> If I use the following to try and get the values, it fails, the date comes
in null for $$entry and a large number followed by $entry for the $($entry)
:
> foreach my $entry (@fields)

>         if ($entry !~ /\$/) {  #this is not an $form_data variable
>                $log .= "$$entry - $($entry)\t";
>        } else {                #it is a form_data variable
>               $log .= "$form_data{$entry}\t";
>        }
>}

blah!

put the variables you are going to use, into an hash
together with form data
     my %combined=%form_data;
     $combined{'date'}=$date;
     ....
then
    @fields = qw(name address phone date);
    foreach my $entry (@fields)

          $log .= "$combined{$entry}\t";
    }


gnari








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

Date: Thu, 12 Feb 2004 23:18:29 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Include data in a perl program?
Message-Id: <c0h1k5$rda$3@wisteria.csv.warwick.ac.uk>


"davido@codethought.nospamforme.com" <me@privacy.net> wrote:
>
> Well, so far I keep running into the same problem.  I get my hash
> reference and all that gets written to the registy is a 'text'
> representation of the TieRegistry data.  Any other ideas would be
> appreciated...
> 
> Example: Win32::TieRegistry=HASH(0x207d420)
> 
> 
> Code:
>     my $eol = undef $/;

Let Perl remember the old value for you. It's much more reliable.

    {
        local $/;  # by default set to undef

>     eval <DATA>;

    }

> 
>     $Registry->{"CUser/Software/VanDyke/SecureFX/File
> Types"}=\%filetypes
>        or die "Can't set the File Types: $^E\n";

Try
        $Registry->{...}{$_} = $filetypes{$_}
            for keys %filetypes;

If %filetypes is a deep structure, then you'll probably have to
recurse over it: it looks like the tied hash stringifies everything,
so references will be destroyed.

Alternatively, you could take your binary dump that you had before and
Base64 encode it. Stick that at the end of your module, then load it
from DATA, decode it and use TieRegistry's load function (with
IO::Scalar if necessary).

Ben

-- 
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
   From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes,        [ Heracles shoots Vulture with arrow. Vulture bursts into ]
 /Alcestis/)        [ flame, and falls out of sight. ]         ben@morrow.me.uk


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

Date: Fri, 13 Feb 2004 01:47:11 GMT
From: XXjbhuntxx@white-star.com (Cosmic Cruizer)
Subject: One more running Perl as a service question
Message-Id: <Xns948DB4EEC3749ccruizermydejacom@64.164.98.50>

I would think this question is more suitable for a Microsoft forum, but 
since I have not received any replies to the questions I posted there, I'm 
back here again.

Now that I am finally successful in turning my Perl scripts into services, 
is it possible to have the service display a console window when the account 
is used to logon? If yes, what changes do I need to make to my service?

This is an application that used to run as a console window, but since it 
also needs to run without an account being logged on, I turned it into a 
service. Since the application is a real-time automated monitoring tool, 
there are times when it is necessary to observe what is scrolling by on the 
screen.

If this isn't the best place to post this question, which group might be 
better suited to answer my question? (I tried the microsoft.public.win2000 
groups.)

Thanks for all the help.


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

Date: Thu, 12 Feb 2004 22:55:03 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: parsing out all data between two words with multiple instances in a file.
Message-Id: <c0h06j$34m$1@news.simnet.is>

"KP" <kprunell@microsoft.com> wrote in message
news:5ffb95e0.0402121309.399e64f4@posting.google.com...
> I'm trying to find a way to parse out all data between two words
> within a file that contains multiple instances where important data
> would be extracted out. The data file would look like such.

[snipped problem]

you forgot to tell us what you have tried, and why it failed.


gnari






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

Date: Thu, 12 Feb 2004 18:21:21 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Perl Sockets Parent/Child Problem
Message-Id: <slrnc2o641.1lj.tadmc@magna.augustmail.com>

Ken Browning <kenbrow@bellsouth.net> wrote:


> Is there a way to flush that buffer _without_ closing
                    ^^^^^
                    ^^^^^

Are you being serious?



   perldoc -q flush

       How do I flush/unbuffer an output filehandle?  Why must I do this?


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


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

Date: Thu, 12 Feb 2004 19:34:41 -0500
From: "Rafal Konopka" <rafalk@comcast.net>
Subject: PERL-SQL and date comparison
Message-Id: <o9GdnXTgs9AChrHdRVn-tA@comcast.com>

I have a script that communicates with the SQL server (MS), and extracts the
data from a list of fields in one or more tables. No problem works like a
charm.

The problem (actually just an annoyance) is the WHERE clause, where I want
to extract the data only if the given field is equal to a certain date.

I'm using Win32:ODBC module

If my clause reads like:
        WHERE open_time='2/5/04/'
                or
        WHERE open_time='2004-02-05'

(or any legal SQL format for that matter)

nothing is retrieved.  It seems that "=" fails. I checked with our SQL guys,
and they claim that the '=' syntax should work.

However, if I use BETWEEN, i.e.
        WHERE open_time BETWEEN '2/5/04 00:00:00' and '2004-02-05 23:59:59'

I get what I want.

Why is that?  Since I want to compare three date fields, I'd rather use the
"=" than three lengthy 'between' statements.

Thanks,

Rafal




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

Date: Fri, 13 Feb 2004 00:41:41 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: PERL-SQL and date comparison
Message-Id: <c0h6g5$2a4$1@wisteria.csv.warwick.ac.uk>


"Rafal Konopka" <rafalk@comcast.net> wrote:
> I have a script that communicates with the SQL server (MS), and extracts the
> data from a list of fields in one or more tables. No problem works like a
> charm.
> 
> The problem (actually just an annoyance) is the WHERE clause, where I want
> to extract the data only if the given field is equal to a certain date.
> 
> I'm using Win32:ODBC module
> 
> If my clause reads like:
>         WHERE open_time='2/5/04/'
>                 or
>         WHERE open_time='2004-02-05'
> 
> (or any legal SQL format for that matter)
> 
> nothing is retrieved.  It seems that "=" fails. I checked with our SQL guys,
> and they claim that the '=' syntax should work.
> 
> However, if I use BETWEEN, i.e.
>         WHERE open_time BETWEEN '2/5/04 00:00:00' and '2004-02-05 23:59:59'
> 
> I get what I want.
> 
> Why is that?  Since I want to compare three date fields, I'd rather use the
> "=" than three lengthy 'between' statements.

This is a problem with your database, not with Perl. Perl just passes
the SQL straight to the database.

At a guess, do you want WHERE open_time IS '2004/02/05' rather than =?

Ben

-- 
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ ben@morrow.me.uk ~                   Jorge Luis Borges, 'The Babylon Lottery'


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

Date: Fri, 13 Feb 2004 10:45:18 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: PERL-SQL and date comparison
Message-Id: <c0h6o1$13quer$1@ID-202028.news.uni-berlin.de>

Rafal Konopka wrote:

> I have a script that communicates with the SQL server (MS), and extracts
> the data from a list of fields in one or more tables. No problem works
> like a charm.
> 
> The problem (actually just an annoyance) is the WHERE clause, where I want
> to extract the data only if the given field is equal to a certain date.
> 
> I'm using Win32:ODBC module
> 
> If my clause reads like:
>         WHERE open_time='2/5/04/'
>                 or
>         WHERE open_time='2004-02-05'
> 
> (or any legal SQL format for that matter)
> 
> nothing is retrieved.  It seems that "=" fails. I checked with our SQL
> guys, and they claim that the '=' syntax should work.
> 
> However, if I use BETWEEN, i.e.
>         WHERE open_time BETWEEN '2/5/04 00:00:00' and '2004-02-05
>         23:59:59'
> 
> I get what I want.
> 
> Why is that?  Since I want to compare three date fields, I'd rather use
> the "=" than three lengthy 'between' statements.
> 
> Thanks,
> 
> Rafal

A very rough guesss ( www.dbforums.com is a better place to ask)

The dates in question could be date/times 

eg dates were first stored internally as 2004-02-05 11:12:18
so open_time='2004-02-05' will never match.

SOLUTION:
Store only the dates
insert into table xxx(open_time) values ('2004-02-05')

NOT insert into table xxx(open_time) values ('2004-02-05 11:12:18')


gtoomey


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

Date: Thu, 12 Feb 2004 19:52:59 -0500
From: "Rafal Konopka" <rafalk@comcast.net>
Subject: Re: PERL-SQL and date comparison
Message-Id: <8cqdnZ3u9rx3grHd4p2dnA@comcast.com>


"Ben Morrow" <usenet@morrow.me.uk> wrote in message
news:c0h6g5$2a4$1@wisteria.csv.warwick.ac.uk...
>
> "Rafal Konopka" <rafalk@comcast.net> wrote:
> > If my clause reads like:
> >         WHERE open_time='2/5/04/'
> > [deleted]
> > nothing is retrieved.  It seems that "=" fails. I checked with our SQL
guys,
> > and they claim that the '=' syntax should work.
> >
> > However, if I use BETWEEN, i.e.
> >         WHERE open_time BETWEEN '2/5/04 00:00:00' and '2004-02-05
23:59:59'
> > deleted.
>
> This is a problem with your database, not with Perl. Perl just passes
> the SQL straight to the database.

That's what I thought.

>
> At a guess, do you want WHERE open_time IS '2004/02/05' rather than =?
>
> Ben

I saw the SQL guys use the "=" syntax and it works.  Perhaps it's the
function of the interpreter.

However, your suggestion 'IS' seems very promising.  I'll try it tomorrow
and let the group know if it works.

Thanks,

Rafal




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

Date: Thu, 12 Feb 2004 19:57:09 -0500
From: "Rafal Konopka" <rafalk@comcast.net>
Subject: Re: PERL-SQL and date comparison
Message-Id: <kN-dnaceIud4vbHd4p2dnA@comcast.com>


"Gregory Toomey" <nospam@bigpond.com> wrote in message
news:c0h6o1$13quer$1@ID-202028.news.uni-berlin.de...
> Rafal Konopka wrote:
>
> A very rough guesss ( www.dbforums.com is a better place to ask)
>
> The dates in question could be date/times
>
> eg dates were first stored internally as 2004-02-05 11:12:18
> so open_time='2004-02-05' will never match.
>
See my reply to Ben.  Invoked from a SQL client, it works,even though you're
right, it is in datetime format.

> SOLUTION:
> Store only the dates
> insert into table xxx(open_time) values ('2004-02-05')
>
> NOT insert into table xxx(open_time) values ('2004-02-05 11:12:18')
>
Unfortunately, I only have read access only.
>
> gtoomey

Thanks,

Rafal




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

Date: Fri, 13 Feb 2004 00:54:37 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: PERL-SQL and date comparison
Message-Id: <c0h76k$40i$1@news.simnet.is>

"Rafal Konopka" <rafalk@comcast.net> wrote in message
news:o9GdnXTgs9AChrHdRVn-tA@comcast.com...
> I have a script that communicates with the SQL server (MS), and extracts
the
> data from a list of fields in one or more tables. No problem works like a
> charm.
>
> The problem (actually just an annoyance) is the WHERE clause, where I want
> to extract the data only if the given field is equal to a certain date.
>
> I'm using Win32:ODBC module
>
> If my clause reads like:
>         WHERE open_time='2/5/04/'
>                 or
>         WHERE open_time='2004-02-05'
>
> (or any legal SQL format for that matter)
>
> nothing is retrieved.  It seems that "=" fails. I checked with our SQL
guys,
> and they claim that the '=' syntax should work.
>
> However, if I use BETWEEN, i.e.
>         WHERE open_time BETWEEN '2/5/04 00:00:00' and '2004-02-05
23:59:59'
>
> I get what I want.
>
> Why is that?  Since I want to compare three date fields, I'd rather use
the
> "=" than three lengthy 'between' statements.

you are using a timestamp field to store a date.
when you store '2004-02-05' what are you are actually storing?
 '2004-02-05 00:00:00' or '2004-02-05 12:00:00' ?

you should be using functions like to_char():
    WHERE to_char(open_time,'YYYY-MM-DD')='2004-02-05'

gnari

P.S.: i do not know anything about MSSQL

P.P.S.: never use date/time datatypes, use varchars with
datetimes normalized like YYYYMMDDhhmmss









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

Date: 12 Feb 2004 17:41:39 -0800
From: bill.standke@medica.com (freewilly3d)
Subject: Problem opening sed pipe
Message-Id: <24fefa25.0402121741.296c2737@posting.google.com>

I'm trying to open the following pipe in perl open(SASPS,"ps -
ef|sed 's/^\(.\{32\}\) /\1/; s/^ *$/*/'|grep sas| sort +0 -1 -d +7 -
8 -d +4 -5 -d +6 -7 -d |") and get a sed error returned. The command
works fine at the command line. The error has something to do with
th *$/ part of the code. This is the message I get back
adwprod:/prod/rptg/bstandke >pssas
sed: 0602-404 Function s/^(.{32}) //; s/^ * cannot be parsed.
any suggestions?


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

Date: Fri, 13 Feb 2004 02:02:35 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Problem opening sed pipe
Message-Id: <x7ptcjzqh0.fsf@mail.sysarch.com>

>>>>> "f" == freewilly3d  <bill.standke@medica.com> writes:

  f> I'm trying to open the following pipe in perl open(SASPS,"ps -
  f> ef|sed 's/^\(.\{32\}\) /\1/; s/^ *$/*/'|grep sas| sort +0 -1 -d +7 -
  f> 8 -d +4 -5 -d +6 -7 -d |") and get a sed error returned. The command
  f> works fine at the command line. The error has something to do with
  f> th *$/ part of the code. This is the message I get back
  f> adwprod:/prod/rptg/bstandke >pssas
  f> sed: 0602-404 Function s/^(.{32}) //; s/^ * cannot be parsed.
  f> any suggestions?

yes, do it all in perl. that code is a waste of good cpu. and even the
ps part can be done with a module.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Fri, 13 Feb 2004 01:09:16 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Regular Expression Help Needed
Message-Id: <402C23A8.A6276BED@acm.org>

Deja User wrote:
> 
> Thanks for the help.  Just to clear things up, this is NOT a homework
> question.. I already graduated from collge in 94.  I am just new to
> regular expressions.  I already did some research on the web and read
> some tutorials.. but still having trouble.

Your best bet is to get the book Mastering Regular Expressions.
http://www.oreilly.com/catalog/regex2/index.html


John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 12 Feb 2004 15:30:34 -0800
From: Arvin Portlock <apollock11@hotmail.com>
Subject: Replacing hundreds of hash keys with their values in a text document
Message-Id: <c0h2au$71e$1@agate.berkeley.edu>

I'm writing a script that replaces the direct form of a
special character with its SDATA equivalent. For example
it would replace all occurences of é with &eacute;. I've
compiled an enormous hash with the "direct" form as the
key and the SDATA version as its value. I can think of two
ways to accomplish this. The first is two loop through all
keys and do a global replace with the correct value:

foreach my $key (keys %characters) {
    $fulltext =~ s/$key/$characters{$key}/g;
}

The second is to process the document character by character
and if the character is in the hash then replace it:

local $/ = undef;
open (FILE, $file);
my $fulltext = <FILE>;
close (FILE);
my @chars = split (//, $fulltext);
foreach my $char (@chars) {
    if ($characters{$char}) {
       print $characters{$char};
    } else {
       print $char;
    }
}

The second seems the faster option, but neither one of them
is exactly and elegant solution. Is there something obvious
I'm missing?

Arvin



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

Date: Thu, 12 Feb 2004 23:45:20 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Replacing hundreds of hash keys with their values in a text document
Message-Id: <c0h36g$suf$1@wisteria.csv.warwick.ac.uk>

Arvin Portlock <apollock11@hotmail.com> wrote:
> I'm writing a script that replaces the direct form of a
> special character with its SDATA equivalent. For example
> it would replace all occurences of é with &eacute;. I've
> compiled an enormous hash with the "direct" form as the
> key and the SDATA version as its value. I can think of two
> ways to accomplish this. The first is two loop through all
> keys and do a global replace with the correct value:
> 
> foreach my $key (keys %characters) {
>     $fulltext =~ s/$key/$characters{$key}/g;
> }
> 
> The second is to process the document character by character
> and if the character is in the hash then replace it:
> 
> local $/ = undef;
> open (FILE, $file);
> my $fulltext = <FILE>;
> close (FILE);
> my @chars = split (//, $fulltext);
> foreach my $char (@chars) {
>     if ($characters{$char}) {
>        print $characters{$char};
>     } else {
>        print $char;
>     }
> }
> 
> The second seems the faster option, but neither one of them
> is exactly and elegant solution. Is there something obvious
> I'm missing?

If you're using 5.8, and don't mind having &#nnnn; instead of named
entities, you can do

    use Encode qw/:fallbacks/;

    $PerlIO::encoding::fallback = FB_HTMLCREF;
    binmode STDOUT, ':encoding(ascii)';

    open my $FILE, '<:encoding(latin1)', $file or die...;
    # or whatever encoding is appropriate
    print while <$FILE>;

Otherwise, I'd do

    open my $FILE, $file or die...;
    while (<$FILE>) {
        s/([^[:ascii:]])/$characters{$1}/g;
        print;
    }

If your %characters doesn't include all the non-ascii in the file, you
could use

    my $to_encode = '[' . (join '', keys %characters) . ']';
    while (<$FILE>) {
        s/($to_encode)/$characters{$1}/g;
        print;
    }

Ben

-- 
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ ben@morrow.me.uk ~                   Jorge Luis Borges, 'The Babylon Lottery'


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

Date: Thu, 12 Feb 2004 23:10:24 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Replacing unicode characters
Message-Id: <c0h150$rda$2@wisteria.csv.warwick.ac.uk>


"Tulan W. Hu" <twhu@lucent.com> wrote:
> "Ben Morrow" <usenet@morrow.me.uk> wrote in
> [snip]
> > If you are using 5.8.0 and have your LC_ALL environment var set to
> > something with UTF8 in, perl will push a :utf8 onto all filehandles by
> > default. This behaviour was disabled in 5.8.1, as it caused *lots* of
> > compatability problems.
>
> How about perl 5.8.2?

5.8.1+ no longer does this *by default*. You can still make the
filehandle UTF8ish manually, or give perl the -C switch to make it
honour the environment vars.

> I got an utf8 file, but I just use regular open to read it
> and I print the string out after I read them. It seems ok.
> I use Unicode::String to convert the lines to latin1.
> The following code seems to work ok.
> 
> use File::Slurp;
> use Unicode::String qw(utf8 latin1);
> 
>         my @l2 = ();
>        @l2 = read_file('filename');
>         foreach my $nline (@l2) {
>                 my $l = utf8($nline);
>                 print "$l";
>                 print $l->latin1;
>         }
> 
> Do you see any problem with this?

None at all if you're happy with it. This is how one would have done
it pre-5.8. The point of 5.8 is that it can now be done like this
instead:

    # state that our file is in UTF8
    open my $FILE, '<:encoding(utf8)', 'filename' or die...;

    # state that we want output in latin1
    binmode STDOUT, ':encoding(latin1)';

    # now just copy it all across
    print while <$FILE>;

which is simpler.

Ben

-- 
"The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching."
     -Assyrian stone tablet, c.2800 BC                         ben@morrow.me.uk


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

Date: 12 Feb 2004 23:44:26 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: tying hashes
Message-Id: <c0h34q$lul$1@mamenchi.zrz.TU-Berlin.DE>

Yuri Shtil  <yshtil@cisco.com> wrote in comp.lang.perl.misc:
> 
> 
> Anno Siegel wrote:
> > Yuri Shtil  <yshtil@cisco.com> wrote in comp.lang.perl.misc:
> > 
> >>Hi all
> >>
> >>I am considering using tie to control access to the properties of our 
> >>objects. The idea is to intercept store/fetch calls and check the 
> >>validity of the keys/values.
> >>
> >>My questions are:
> >>
> >>	- has anyone used tie for this purpose
> > 
> > 
> > You mean, checking the values that go into an object?  Yes, that's one of
> > the standard applications of tie(), sometimes in conjunction with lvalue
> > accessors or an  overloaded "%{}".
> > 
> > 
> >>	- are there any performance or other drawbacks
> > 
> > 
> > Tied variables are slow.  Also, to tie a hash you need to define quite
> > a number of methods, though modules like Tie::Hash help with that.
> > 
> > 
> >>         - are there better alternatives to tie
> > 
> > 
> > Plain standard accessors do the same job more directly.
> > 
> > I see two primary reasons for tie: You may want the fancy interface, or you
> > may want to send other parts of the program a hash that is more than meets
> > the eye.  
> > 
> > Anno
> 
> Could you elaborate (or point to an elaboration) on "lvalue accessors", 
> "Plain standard accessors" and overloaded "%{}"?

With standard accessors I mean typical things like

    sub age {
        my $self = shift;
        $self->{ name} = shift if @_;
        $self->{ name};
    }

 ...or obvious variations like get_name/set_name pairs.  These have in
common that when an access happens you know whether it's read or write
access and in the latter case you know the new value.  So you have every
chance to check the value for validity before it is assigned.  The user
has to say "$obj->name( 'August')" to assign a name.

With lvalue accessors (see perlsub for the technicalities of lvalue subs)

    sub age :lvalue { $self->{ name} }

the user gets the intuitive "$self->name = 'August'", but you have to expose
the field "$self->{ name}" completely.  When "age()" is called you don't
even know if it's read or write access, though there are modules...

I have assumed a hash structure for the underlying object.  If you replace
that with a tied hash, you re-gain control over read-write access and you
get to see the value again before it is stored in the object.  But that's
quite a price to pay for the user-friendly interface.

Similar considerations apply when you base an interface on the overloading
of references, as "%{}".  (Technical details in "perldoc overload", obviously.)
Again, you have to expose (part of) your object to the user, and again you
can re-gain control by replacing the underlying structure with a tied one.

Anno


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

Date: Thu, 12 Feb 2004 16:15:38 -0800
From: Yuri Shtil <yshtil@cisco.com>
Subject: Re: tying hashes
Message-Id: <402C172A.5030001@cisco.com>

Anno Siegel wrote:
> Yuri Shtil  <yshtil@cisco.com> wrote in comp.lang.perl.misc:
> 
>>
>>Anno Siegel wrote:
>>
>>>Yuri Shtil  <yshtil@cisco.com> wrote in comp.lang.perl.misc:
>>>
>>>
>>>>Hi all
>>>>
>>>>I am considering using tie to control access to the properties of our 
>>>>objects. The idea is to intercept store/fetch calls and check the 
>>>>validity of the keys/values.
>>>>
>>>>My questions are:
>>>>
>>>>	- has anyone used tie for this purpose
>>>
>>>
>>>You mean, checking the values that go into an object?  Yes, that's one of
>>>the standard applications of tie(), sometimes in conjunction with lvalue
>>>accessors or an  overloaded "%{}".
>>>
>>>
>>>
>>>>	- are there any performance or other drawbacks
>>>
>>>
>>>Tied variables are slow.  Also, to tie a hash you need to define quite
>>>a number of methods, though modules like Tie::Hash help with that.
>>>
>>>
>>>
>>>>        - are there better alternatives to tie
>>>
>>>
>>>Plain standard accessors do the same job more directly.
>>>
>>>I see two primary reasons for tie: You may want the fancy interface, or you
>>>may want to send other parts of the program a hash that is more than meets
>>>the eye.  
>>>
>>>Anno
>>
>>Could you elaborate (or point to an elaboration) on "lvalue accessors", 
>>"Plain standard accessors" and overloaded "%{}"?
> 
> 
> With standard accessors I mean typical things like
> 
>     sub age {
>         my $self = shift;
>         $self->{ name} = shift if @_;
>         $self->{ name};
>     }
> 
> ...or obvious variations like get_name/set_name pairs.  These have in
> common that when an access happens you know whether it's read or write
> access and in the latter case you know the new value.  So you have every
> chance to check the value for validity before it is assigned.  The user
> has to say "$obj->name( 'August')" to assign a name.
> 
> With lvalue accessors (see perlsub for the technicalities of lvalue subs)
> 
>     sub age :lvalue { $self->{ name} }
> 
> the user gets the intuitive "$self->name = 'August'", but you have to expose
> the field "$self->{ name}" completely.  When "age()" is called you don't
> even know if it's read or write access, though there are modules...
> 
> I have assumed a hash structure for the underlying object.  If you replace
> that with a tied hash, you re-gain control over read-write access and you
> get to see the value again before it is stored in the object.  But that's
> quite a price to pay for the user-friendly interface.
> 
> Similar considerations apply when you base an interface on the overloading
> of references, as "%{}".  (Technical details in "perldoc overload", obviously.)
> Again, you have to expose (part of) your object to the user, and again you
> can re-gain control by replacing the underlying structure with a tied one.
> 
> Anno

I did a quick read on overloading. It seems that it is not what I want 
since I want to control some objects, but not all objects of the same type.

Thank you very much. I learned more about Perl.

Yuri.



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

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


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