[17162] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4574 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 10 18:15:48 2000

Date: Tue, 10 Oct 2000 15:15:23 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <971216123-v9-i4574@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 10 Oct 2000     Volume: 9 Number: 4574

Today's topics:
        Reading a whole file into a string <g.soper@soundhouse.co.uk>
    Re: Reading a whole file into a string (Brett W. McCoy)
    Re: Reading a whole file into a string <uri@sysarch.com>
    Re: Reading a whole file into a string <Jonathan.L.Ericson@jpl.nasa.gov>
    Re: Reading a whole file into a string <uri@sysarch.com>
    Re: regex matching troubles <tim@ipac.caltech.edu>
    Re: sorting <uri@sysarch.com>
    Re: SQL Parser <jeff@vpservices.com>
    Re: SQL Parser (Randal L. Schwartz)
    Re: SQL Parser <jesse.van.oort@home.nl>
    Re: SQL Parser (Randal L. Schwartz)
    Re: SQL Parser <jeff@vpservices.com>
    Re: SQL Parser <jesse.van.oort@home.nl>
    Re: SQL Parser (Randal L. Schwartz)
    Re: SQL Parser (Randal L. Schwartz)
    Re: SQL Parser <jesse.van.oort@home.nl>
    Re: SQL Parser (brian d foy)
        String convertion problem <sylvain2k@sympatico.ca>
    Re: system command <tim@ipac.caltech.edu>
    Re: system command <tzz@iglou.com>
    Re: system command <tim@ipac.caltech.edu>
    Re: system command (brian d foy)
    Re: system command rbfitzpa@my-deja.com
    Re: the fastest way to test String A included by String (Craig Berry)
        Unbuffered read from serial device ? <noemail@us.com>
    Re: Unbuffered read from serial device ? <uri@sysarch.com>
    Re: UNIX/PERL question (Clay Irving)
    Re: UNIX/PERL question <jeffp@crusoe.net>
    Re: UNIX/PERL question <dperham@dperham.eng.tvol.net>
        Writing multple lines to a file at once? billgerba@my-deja.com
    Re: Writing multple lines to a file at once? <jeff@vpservices.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 10 Oct 2000 21:01:26 +0100
From: Geoff Soper <g.soper@soundhouse.co.uk>
Subject: Reading a whole file into a string
Message-Id: <4a0b7358d6g.soper@soundhouse.co.uk>

I would like to print a HTML form with a textarea field containing the
contents of a file of text. I'm using the CGI.pl module so I need to
provide the file contents in the argument.

Reading the perlfaq5 I see the part about reading a whole file in one go.
I'm pretty sure this is what I want to do and have tried:

    $article_location  = $news_location . $file;
    $article  = 'cat $article_location';
    print textarea(
        -name => "article",
        -default => $article,
        -rows => 20,
        -colums => 60,
    );

The " $var = 'cat $file' " part is the part I got from the FAQ, this
doesn't look right to me but I thought I'd try it anyway, I've obviously
misunderstood something so if somebody could point out what I'd be most
grateful!

-- 
Geoff Soper
g.soper@soundhouse.co.uk
Take a look at the Soundhouse page http://www.soundhouse.co.uk/


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

Date: Tue, 10 Oct 2000 20:45:37 GMT
From: bmccoy@news.speakeasy.org (Brett W. McCoy)
Subject: Re: Reading a whole file into a string
Message-Id: <slrn8u700h.krs.bmccoy@chapelperilous.net>

On Tue, 10 Oct 2000 21:01:26 +0100, Geoff Soper <g.soper@soundhouse.co.uk>
wrote:

>The " $var = 'cat $file' " part is the part I got from the FAQ, this
>doesn't look right to me but I thought I'd try it anyway, I've obviously
>misunderstood something so if somebody could point out what I'd be most
>grateful!

Except that it won't work.  What you want is $var = `cat $file`.  Note the
backticks rather than single quotes. Otherwise your $var will just be
holding "cat <contents of $file>".  That will definitely slurp up the
contents into a single scalar.  Think very carefully about whether or not
you really want to gobble up the entire contents and dump it into a
textarea (some versions of Netscape, notably on Solaris and Linux, will
start thrashing the drive because of a buggy textarea implementation that
chokes when the textarea has a certain amount of text in it), requiring
you to login in remotely to kill the process!) If you are developing a
content management kind of thing, you might want to break your article up
into logical chunks.

-- 
Brett W. McCoy
                                              http://www.chapelperilous.net
---------------------------------------------------------------------------
Everything can be filed under "miscellaneous".


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

Date: Tue, 10 Oct 2000 20:41:53 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Reading a whole file into a string
Message-Id: <x7snq41l9p.fsf@home.sysarch.com>

>>>>> "GS" == Geoff Soper <g.soper@soundhouse.co.uk> writes:

  GS>     $article  = 'cat $article_location';

  GS> The " $var = 'cat $file' " part is the part I got from the FAQ, this
  GS> doesn't look right to me but I thought I'd try it anyway, I've obviously
  GS> misunderstood something so if somebody could point out what I'd be most
  GS> grateful!

you need better glasses or larger fonts. the proper char pair to execute
a command is `` which are commonly called a back ticks. you used single
quotes instead.

since this is cgi so you want to be fast, there are much better ways to
read in a whole file. search dejanews for them as this has been
discussed many times.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Tue, 10 Oct 2000 13:54:13 -0700
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: Reading a whole file into a string
Message-Id: <39E381F5.B8C6DBC3@jpl.nasa.gov>

Geoff Soper wrote:
> The " $var = 'cat $file' " part is the part I got from the FAQ, this
> doesn't look right to me but I thought I'd try it anyway, I've obviously
> misunderstood something so if somebody could point out what I'd be most
> grateful!

Look carefully.  It should be ` not '.  $var = qx(cat $file) would be
clearer.    You can avoid forking a process with:

  {
    local undef $/;
    open FH, $file or die "can't open $file: $!";
    $var = <FH>;
  };

Jon
-- 
Knowledge is that which remains when what is
learned is forgotten. - Mr. King


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

Date: Tue, 10 Oct 2000 21:52:13 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Reading a whole file into a string
Message-Id: <x7n1gc1i0j.fsf@home.sysarch.com>

>>>>> "JE" == Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov> writes:


  JE>   {
  JE>     local undef $/;

huh? local $/ is just fine. i am not even sure the above is legal but i
am not going to try it.

  JE>     open FH, $file or die "can't open $file: $!";
  JE>     $var = <FH>;

you might want to localize the handle as well. if you do, it will be
closed for you on exiting the block.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Tue, 10 Oct 2000 12:11:27 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: regex matching troubles
Message-Id: <39E369DF.D8E043F9@ipac.caltech.edu>

Josiah wrote:
> $_ = 'str josiah';
> 
>     if(/str[(\s\$)(\s\()(\$)]/) {
>         print 'matched';
>     } else {
>         print 'no match';
>     }
> 
> now, in my thinking it should print "no match" because "str" is NOT
> followed by "\s\(" or "\s\(" or "\$".
> but when i run it on my system, it prints "match";

Read perlre again (or for the first time). Square brackets don't do what you
think they do. I think what you were trying to write was

/str((\s\$)|(\s\()|(\$))/

 ... but this is probably more like what you were thinking:

/\bstr\s*(\$|\()/

> 
> ... that is, if str is preceded by a $, then do NOT match.

/(?<!\$)\bstr\s*(\$|\()/

> 
> basically, i am trying to figure out wether the op in question is 
> actually a sub call, i.e. looks like a sub call, or is just a word in 
> text, according to perl.

That's alot harder to do in the general case than you realize. How about
'str @a', 'str -1'? And why don't you think 'str foo ...' is a sub call? What
about 'str length $string'? And what about 'qq/str(1)/'?

Unless you have control over the way the code is written, maybe you'd better
think of a better solution than trying to parse Perl.

Just a suggestion.

--

-- Tim Conrow         tim@ipac.caltech.edu                           |


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

Date: Tue, 10 Oct 2000 18:37:42 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: sorting
Message-Id: <x73di435l5.fsf@home.sysarch.com>

>>>>> "RL" == Robert Lund <noone@dontbother.com> writes:

  RL> I've tried reading the FAQ's and books, but am still stuck...

reread them. lather. rinse. repeat.

  RL> I want to sort a list of lists, by the second list of the list of
  RL> lists....  here's the code I'm using.

do you mean sort by te entire second list? that makes little sense. if
you mean by the second field it makes sense. you don't sort by lists,
you sort by fields (or multiple fields).

  RL> @newlist = sort { @{$oldlist[1]}[$a] cmp @{$oldlist[1]}[$b] } @oldlist;

  RL> The values of the second element of the outer list are strings,
  RL> that's why I'm using cmp.... why is this not working?

the cmp may be right but what are you comparing? if @oldlist is a LOL
then it really is a list of array refs. so $a and $b will be array
refs. you don't index with array refs, you dereference them. this is
probably what you want but i can't be sure without any data:

@newlist = sort { $a->[1] cmp $b->[1] } @oldlist;

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Tue, 10 Oct 2000 11:06:59 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: SQL Parser
Message-Id: <39E35AC3.77950C4E@vpservices.com>

Jesse van Oort wrote:
> 
> On 10 Oct 2000 09:41:34 -0700, merlyn@stonehenge.com (Randal L.
> Schwartz) wrote:
> 
> >>>>>> "Jesse" == Jesse van Oort <jesse.van.oort@home.nl> writes:
> >
> >Jesse> Hi All,
> >Jesse> I need to write a program that scans a fortran source-file for
> >Jesse> sql-statements and returns a hash with column and table usages.
> >Jesse> I am able to extract the entire sql-statement, but am quite stuck at
> >Jesse> the point where I want to scan for used tables.
> >Jesse> To be more specific: I end up with an array consisting of tables and
> >Jesse> their aliasses.
> >Jesse> Not every table has an alias though, so my array currently looks like
> >Jesse> this: 'table1', ',table2','a2',',table3','a3',',table4',',table5',
> >Jesse> etc,  where the tables are preceded by a comma, except for the first
> >Jesse> one.
> >Jesse> Can someone advise me on writing a good consistant algorithm for this?
> >Jesse> What I want is a hash like: table => alias (or empty if there isn't an
> >Jesse> alias).
> >
> >You can look at SQL::Statement in the CPAN, presuming you can isolate
> >what parts of your intput text are SQL and what parts are Fortran.
> >
> >If that's the wrong weight, you can construct your own parser
> >with Parse::RecDescent (also in the CPAN).

I have already begun work on translating SQL::Statement into a
Parse::RecDescent grammar.  But if I  understand what you have
described, you need something much simpler -- you have already pulled
out the table names, you just don't know which are table names and which
are aliases, is that correct?  If so SQL::Statement will be of no use
since it doesn't deal with aliases.  Perhaps we could help if you gave
us some more details of what you already have (e.g. what a few of the
statements you have extracted from the FORTRAN look like, and what info
you want to further extract from them).

-- 
Jeff


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

Date: 10 Oct 2000 11:38:16 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: SQL Parser
Message-Id: <m1itr0v8x3.fsf@halfdome.holdit.com>

>>>>> "Jeff" == Jeff Zucker <jeff@vpservices.com> writes:

Jeff> I have already begun work on translating SQL::Statement into a
Jeff> Parse::RecDescent grammar.

Why are you doing that when there's already a nice sql_yacc.y parser?
Are you trying to avoid any C compilation?

-- 
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: Tue, 10 Oct 2000 18:39:24 GMT
From: Jesse van Oort <jesse.van.oort@home.nl>
Subject: Re: SQL Parser
Message-Id: <7fn6uscrt2i171nvfgqggq0fdafe2pkj3o@4ax.com>

On Tue, 10 Oct 2000 11:06:59 -0700, Jeff Zucker <jeff@vpservices.com>
wrote:

>I have already begun work on translating SQL::Statement into a
>Parse::RecDescent grammar.  But if I  understand what you have
>described, you need something much simpler -- you have already pulled
>out the table names, you just don't know which are table names and which
>are aliases, is that correct?  If so SQL::Statement will be of no use
>since it doesn't deal with aliases.  Perhaps we could help if you gave
>us some more details of what you already have (e.g. what a few of the
>statements you have extracted from the FORTRAN look like, and what info
>you want to further extract from them).


Hi Jeff,

What a pity that SQL-Statement doesn't deal with aliases.
You are right, I have a routine that extracts everything between
'FROM' and 'WHERE' (or ORDER, GROUP etc.), but I am having
difficulties recognizing the tables and their aliases.

The next step will be extracting everything between SELECT and FROM,
replacing the aliases with the real names and checking al tables in
the FROM for occurences of the columns that have no alias. Are you
still with me?

The PRO*Fortran code looks like this:

<snip>

        IF (DEBUG) THEN
            WRITE(6,9000) 'Jaar heffing           : ',
     *                     JAAR_HEFFING
            WRITE(6,9010) 'Max. betalingsverschil : ',
     *                     SYS_MAX_BET_VERSCH
         ENDIF

C
--------------------------------------------------------------------
C        Definieren van de cursor voor openstaande
ontvangstmachtigingen
C
--------------------------------------------------------------------
         EXEC SQL DECLARE COVM CURSOR FOR
     *      SELECT SUBSTR(R.KODE_GEBIED,6,1),
     *             AANGIFTE_NUMMER,
     *             SUBSTR(AANGIFTE_NUMMER,1,11),
     *             SUBSTR(AANGIFTE_NUMMER,1,9),
C Y2K BUGFIX
C     *             DATUM_VERVAL,
     *             TO_CHAR(DATUM_VERVAL,'DD-MM-YYYY'),
     *             BEDRAG_HEFFING,
     *             BEDRAG_VERHOOG,
     *             BEDRAG_KOSTEN,
     *             BEDRAG_RENTE,
     *             BEDRAG_TOTAAL,
     *             BEDRAG_BETALING,
     *             NVL(BEDRAG_KWIJTSCH,0),
     *             NVL(BEDRAG_UITSTEL,0),
     *             BEDRAG_OPEN,
     *             DECODE(IND_REGELING,0,' ','X'),
     *             DECODE(IND_INVORDERING,0,'              ',
     *                  'X, '||TO_CHAR(DAT_INVORDERING
     *                                         ,'DD-MM-YYYY')),
     *             DECODE(IND_STOPZETTING,0,' ','X'),
     *             DECODE(IND_VERSNELDE_INVORDERING,0,' ','X'),
     *             KEREN_GEMAAND
     *      FROM   MSWOVM
     *            ,MSWBDR B
     *            ,MSWRPK R
     *      WHERE  SUBSTR(AANGIFTE_NUMMER,12,4) != '0001'
     *      AND    STATUS < 9
     *      AND    (BEDRAG_OPEN - NVL(BEDRAG_UITSTEL,0)) > 0
     *      AND    BEDRAG_OPEN > :SYS_MAX_BET_VERSCH
     *      AND    SUBSTR(AANGIFTE_NUMMER,10,2) = :JAAR_HEFFING
     *      AND    B.MSW_NUMMER  = SUBSTR(AANGIFTE_NUMMER,1,9)
     *      AND    R.POSTKODE    = SUBSTR(B.POSTKODE_ADRES,1,4)
     *      AND    R.KODE_REGIO  = 'ONTV'
     *      AND     SUBSTR(R.KODE_GEBIED,6,1) LIKE 
     *                DECODE(:OCT_REGIO,'A','%',:OCT_REGIO)
     *      ORDER BY SUBSTR(R.KODE_GEBIED,6,1),AANGIFTE_NUMMER 
         IF (SQLCDE .LT. 0) CALL FOUTAFHANDELING

C
--------------------------------------------------------------------
C        Openen van de cursor voor openstaande ontvangstmachtigingen
C
--------------------------------------------------------------------


</snip>

You see, the SQL starts after EXEC SQL and is entirely preceded by
asterisks (by the PRO*Fortran compiler).

I don't have my routine at hand, since I'm figuring this one out at
home and forgot to bring it with me.

Any Ideas to safely extract the tables etc?

Jesse









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

Date: 10 Oct 2000 11:47:45 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: SQL Parser
Message-Id: <m1bswsv8ha.fsf@halfdome.holdit.com>

>>>>> "Jesse" == Jesse van Oort <jesse.van.oort@home.nl> writes:

Jesse> What a pity that SQL-Statement doesn't deal with aliases.
Jesse> You are right, I have a routine that extracts everything between
Jesse> 'FROM' and 'WHERE' (or ORDER, GROUP etc.), but I am having
Jesse> difficulties recognizing the tables and their aliases.

Jesse> The next step will be extracting everything between SELECT and FROM,
Jesse> replacing the aliases with the real names and checking al tables in
Jesse> the FROM for occurences of the columns that have no alias. Are you
Jesse> still with me?

Sounds like fun.  You'll need to do pretty thorough SQL expression
syntax parsing though, not trivial with a few regex unless you want
only a "mostly" solution.

So, wait until Jeff gets his P::RD grammar done, or be prepared
to duplicate the effort yourself.

-- 
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: Tue, 10 Oct 2000 11:54:33 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: SQL Parser
Message-Id: <39E365E9.86B186AA@vpservices.com>

"Randal L. Schwartz" wrote:
> 
> >>>>> "Jeff" == Jeff Zucker <jeff@vpservices.com> writes:
> 
> Jeff> I have already begun work on translating SQL::Statement into a
> Jeff> Parse::RecDescent grammar.
> 
> Why are you doing that 

Because Tim Bunce and Jochen Wiedmann (the author of the sql_yacc.y
parser) encouraged me to. 

> when there's already a nice sql_yacc.y parser?

I assume you mean the one that is part of SQL::Statement?  If not,
please tell me about it.  The SQL::Statement is nice as far as it goes,
it just doesn't go far enough (in several directions).

> Are you trying to avoid any C compilation?

Yes.

Have a better idea? I'm all ears. (seriously)

-- 
Jeff


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

Date: Tue, 10 Oct 2000 19:12:00 GMT
From: Jesse van Oort <jesse.van.oort@home.nl>
Subject: Re: SQL Parser
Message-Id: <0fp6usohpiqm00lhu5gbbqfm3pb6dm2hav@4ax.com>

On 10 Oct 2000 11:47:45 -0700, merlyn@stonehenge.com (Randal L.
Schwartz) wrote:

>>>>>> "Jesse" == Jesse van Oort <jesse.van.oort@home.nl> writes:
>
>Jesse> What a pity that SQL-Statement doesn't deal with aliases.
>Jesse> You are right, I have a routine that extracts everything between
>Jesse> 'FROM' and 'WHERE' (or ORDER, GROUP etc.), but I am having
>Jesse> difficulties recognizing the tables and their aliases.
>
>Jesse> The next step will be extracting everything between SELECT and FROM,
>Jesse> replacing the aliases with the real names and checking al tables in
>Jesse> the FROM for occurences of the columns that have no alias. Are you
>Jesse> still with me?
>
>Sounds like fun.  You'll need to do pretty thorough SQL expression
>syntax parsing though, not trivial with a few regex unless you want
>only a "mostly" solution.
>
>So, wait until Jeff gets his P::RD grammar done, or be prepared
>to duplicate the effort yourself.

Yes it's fun. It is also a chance to show what Perl is up to.(I'm
doing al the tooling at the moment, and most of it is in perl).

Perhaps if I explain my algorythm you still have some advice for me?

1. I extract the entire SQL-statement and put it in an array. This
works!

2. I split the array up in single words and search the FROM. There I
extract the tables and their aliases. This also works.

3. Now the tricky bit: I set $first to 'y' to indicate my first found
table. You see, my found-table array looks like: 'table1 ,table2
alias2 ,table3 alias3'.

So Between an alias and a table is always a comma. In other words, if
there's no comma, it's the alias from the previous table.
My problem is the first table, which in this example has no alias.
Also table nr 4 may not have an alias.

Ok, $first eq 'y', next step is to see if the next word has a comma.
If yes, then i'ts a table. If the next one doesn't, it's an alias.

I want to put everything in a hash, so I can use it later in my 'Quest
for the Columns'.



Any advice on my approach?



Jesse

Do you per chance have any advice on how to


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

Date: 10 Oct 2000 12:13:07 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: SQL Parser
Message-Id: <m1zokctsqk.fsf@halfdome.holdit.com>

>>>>> "Jeff" == Jeff Zucker <jeff@vpservices.com> writes:

Jeff> Because Tim Bunce and Jochen Wiedmann (the author of the sql_yacc.y
Jeff> parser) encouraged me to. 

Yeah, now that I looked at how subsetty the current SQL::Statement
is, I'm itching to help you along with yours.  Go, Jeff, go!

-- 
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: 10 Oct 2000 12:28:56 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: SQL Parser
Message-Id: <m1r95ots07.fsf@halfdome.holdit.com>

>>>>> "Jesse" == Jesse van Oort <jesse.van.oort@home.nl> writes:

Jesse> Perhaps if I explain my algorythm you still have some advice for me?

Jesse> 1. I extract the entire SQL-statement and put it in an array. This
Jesse> works!

Array?  You mean string?  In Perl, a scalar (string) is not an array.

Jesse> 2. I split the array up in single words and search the FROM. There I
Jesse> extract the tables and their aliases. This also works.

Jesse> 3. Now the tricky bit: I set $first to 'y' to indicate my first found
Jesse> table. You see, my found-table array looks like: 'table1 ,table2
Jesse> alias2 ,table3 alias3'.

Jesse> So Between an alias and a table is always a comma. In other words, if
Jesse> there's no comma, it's the alias from the previous table.
Jesse> My problem is the first table, which in this example has no alias.
Jesse> Also table nr 4 may not have an alias.

Jesse> Ok, $first eq 'y', next step is to see if the next word has a comma.
Jesse> If yes, then i'ts a table. If the next one doesn't, it's an alias.

Or perhaps more simply:

    ## presume a single SQL statement is in $input

    ($tables) = /\bfrom\b(.*?)\bwhere\b/i or die "Cannot find tables in $input";
    @tables = split /\s*,\s*/, $tables;
    for (@tables) {
      ($name, $alias) = split /\s+/;
      if (defined $alias) {
        print "table $name has alias $alias\n";
      } else {
        print "table $name has no alias\n";
      }
    }

Quick and dirty, but does that help?

print "Just another Perl hacker,"

-- 
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: Tue, 10 Oct 2000 19:44:18 GMT
From: Jesse van Oort <jesse.van.oort@home.nl>
Subject: Re: SQL Parser
Message-Id: <skr6uss7tuv662uvumi9hact6e2smjset1@4ax.com>

Once upon a sunny day, a furry little animal named
merlyn@stonehenge.com (Randal L. Schwartz) squeaked:

>
>Jesse> 1. I extract the entire SQL-statement and put it in an array. This
>Jesse> works!
>
>Array?  You mean string?  In Perl, a scalar (string) is not an array.

Ah yes, of course you're right! But it is an array of strings, so I
can easily loop through.

>
>Jesse> Ok, $first eq 'y', next step is to see if the next word has a comma.
>Jesse> If yes, then i'ts a table. If the next one doesn't, it's an alias.
>
>Or perhaps more simply:
>
>    ## presume a single SQL statement is in $input
>
>    ($tables) = /\bfrom\b(.*?)\bwhere\b/i or die "Cannot find tables in $input";
>    @tables = split /\s*,\s*/, $tables;
>    for (@tables) {
>      ($name, $alias) = split /\s+/;
>      if (defined $alias) {
>        print "table $name has alias $alias\n";
>      } else {
>        print "table $name has no alias\n";
>      }
>    }
>
>Quick and dirty, but does that help?
>
>print "Just another Perl hacker,"

Why didn't I think of something like that!? ;-)
I like quick and dirty (and so does my boss) as long as its thorough.

Well, thanks for setting me off into the right direction and showing
me I really have to catch up on my regexes (Not my strongest feature,
alas, but hey, I'm pretty sure I'm a better dancer ;-) ).


Thanks,

Jesse




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

Date: Tue, 10 Oct 2000 16:58:43 -0400
From: brian@smithrenaud.com (brian d foy)
Subject: Re: SQL Parser
Message-Id: <brian-ya02408000R1010001658430001@news.panix.com>

In article <m1itr0v8x3.fsf@halfdome.holdit.com>, merlyn@stonehenge.com (Randal L. Schwartz) posted:

> >>>>> "Jeff" == Jeff Zucker <jeff@vpservices.com> writes:
> 
> Jeff> I have already begun work on translating SQL::Statement into a
> Jeff> Parse::RecDescent grammar.
> 
> Why are you doing that when there's already a nice sql_yacc.y parser?
> Are you trying to avoid any C compilation?

the SQL::Statement module uses "Perl exceptions" so it dies of it's
own accord.  this makes the programmer do various acrobatics to get
around these oddities.

RecDescent may not be the way to go, but a different module is 
definately desireable IMO.

-- 
brian d foy                    
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Mongers <URL:http://www.perl.org/>


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

Date: Tue, 10 Oct 2000 17:56:46 -0400
From: "Sylvain Perreault" <sylvain2k@sympatico.ca>
Subject: String convertion problem
Message-Id: <teME5.7006$0d3.173971@weber.videotron.net>

Hi,

I have a little problem...

I used a web form... and I want to write in a file the content of this
form...

my problem is here...

I have a <textarea> in my form... and I want the content of this textarea on
1 line... WITH the \n convert to <br>... like:

This is a test<br> and it's working

I get:

This is a test
and it's working...

I've tried:

   $value =~ tr/\n/<br>/;

and it doesn't work...

Can you help me??? Thanks a lot!




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

Date: Tue, 10 Oct 2000 11:44:03 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: system command
Message-Id: <39E36373.FA6F2B6D@ipac.caltech.edu>

brian d foy wrote:
> 
> In article <m366n1aa27.fsf@dhcp11-177.support.tivoli.com>, Ren Maddox 
> <ren.maddox@tivoli.com> posted:
> 
> > system("perl rss2html.pl $urlsource > myfile.html");
> 
> don't use the single argument version of system().  use it
> in the list form:
> 
>    system( $coomand, $options, $arguments ).

In this case he's using '>' to redirect output, which requires the shell, so if
he uses system, he may as well use the single arg form. Though certainly it
would be better for security to do 

open(PIPE,"perl rss2html.pl $urlsource |") or die "$!";
@op = <PIPE>;

 ... etc. to eliminate the shell (after properly $urlsource).

See perlsec.

Though best of all would be to simply write rss2html.pl as a library or module
and 'require' or 'use' it.

--

-- Tim Conrow         tim@ipac.caltech.edu                           |


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

Date: 10 Oct 2000 14:52:22 -0500
From: Ted Zlatanov <tzz@iglou.com>
Subject: Re: system command
Message-Id: <971203790.25649@iglou.com>

In article <slrn8u5fah.fbo.rgarciasuarez@rafael.kazibao.net>, Rafael Garcia-Suarez wrote:
>BTW, why use system() to execute a perl script?

I can think of two reasons:

- the script doesn't use the Perl interpreter you know about

- flags are passed in the shebang line, e.g. -T for taint checking

-- 
Teodor Zlatanov <tzz@iglou.com>
"Brevis oratio penetrat colos, longa potatio evacuat ciphos." -Rabelais


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

Date: Tue, 10 Oct 2000 12:18:40 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: system command
Message-Id: <39E36B90.763230EF@ipac.caltech.edu>

Oops.

Tim Conrow wrote:
> open(PIPE,"perl rss2html.pl $urlsource |") or die "$!";
> @op = <PIPE>;
> 
> ... etc. to eliminate the shell (after properly $urlsource).
                                                 ^ 
                                             untainting
> 
> See perlsec.

(The OP, not you brian).

--

-- Tim Conrow         tim@ipac.caltech.edu                           |


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

Date: Tue, 10 Oct 2000 16:56:38 -0400
From: brian@smithrenaud.com (brian d foy)
Subject: Re: system command
Message-Id: <brian-ya02408000R1010001656380001@news.panix.com>

In article <971203790.25649@iglou.com>, Ted Zlatanov <tzz@iglou.com> posted:

> In article <slrn8u5fah.fbo.rgarciasuarez@rafael.kazibao.net>, Rafael Garcia-Suarez wrote:
> >BTW, why use system() to execute a perl script?
> 
> I can think of two reasons:
> 
> - the script doesn't use the Perl interpreter you know about
> 
> - flags are passed in the shebang line, e.g. -T for taint checking

it doesn't matter that it is a Perl script.  you would need to
ask the question "Why use system at all?".  if you want to run
external programs, then it is not unreasonable that some of those
external programs might be written in Perl. :)

-- 
brian d foy                    
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Mongers <URL:http://www.perl.org/>


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

Date: Tue, 10 Oct 2000 21:29:57 GMT
From: rbfitzpa@my-deja.com
Subject: Re: system command
Message-Id: <8s01ob$qps$1@nnrp1.deja.com>

I've had problems with this before, make sure all your paths are
absolute within your scripts. Even though you might be able to execute
the script on the command line doesn't mean that the apache user that
executes the script via cgi has the same environment.

In article <39e1c679_2@news.eclipse.net>,
  "John Menke" <john@eagleinfosystems.com> wrote:
> I am running ActivePerl on a windows 98 machine and want to run a perl
> script from another perl script.
>
> I have read about the system command and want to use it to execute the
> second script then return to the first script.
>
> The path to my second script is f:/rss2/rss2html.pl
>
> What I want to do is call the second script and direct it's output to
a html
> file called myfile.html.  I have been trying this with no success.
> ($urlsource is a command line argument to rss2html.pl)
>
>     my $progpath = "f:/rss2/";
>     @args = ("rss2html | myfile.html", $urlsource);
>     system $progpath (@args) == 0
>  or print "not working";
>
> can anyone help me with this?
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 10 Oct 2000 18:54:29 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: the fastest way to test String A included by String B
Message-Id: <su6pf59qs92175@corp.supernews.com>

Lucas (wstsoi@hongkong.com) wrote:
: Hi all,
: 
: I got two strings,
: @A = ("apple", "banana", "cherry", "cocount", "pear", "peach", "mango");
: @B = ("cherry", "banana", "pear");
: 
: what is the fastest way to test whether B is a subset of A?

Not necessarily fastest, but this has a pleasing directness to it:

  my %h;
  @h{@A, @B} = (1) x (@A + @B);
  my $is_subset = keys %h == @A;


-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Quidquid latine dictum sit, altum viditur."
   |


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

Date: Tue, 10 Oct 2000 15:08:03 -0500
From: "Gordon Durnell" <noemail@us.com>
Subject: Unbuffered read from serial device ?
Message-Id: <su6tp5j811gi7c@corp.supernews.com>

Is it possible to use getc (or something similar) to read from a serial
device and exit if there is nothing in the input buffer?  Alternately, a
function that returns the number of bytes currently in the input buffer
would do the trick.

What I really need is a sysread that fails if a specified string is not read
within a specified time.
i.e.   read_with_timeout( file_handle, string_to_detect, timeout );

Is this really beyond the scope of standard Perl?

--

Gordon Durnell - Megavolt
Springfield MO
gdurnell_megavolt@hotmail.com




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

Date: Tue, 10 Oct 2000 20:18:52 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Unbuffered read from serial device ?
Message-Id: <x7vgv01mc3.fsf@home.sysarch.com>

>>>>> "GD" == Gordon Durnell <noemail@us.com> writes:

  GD> Is it possible to use getc (or something similar) to read from a serial
  GD> device and exit if there is nothing in the input buffer?  Alternately, a
  GD> function that returns the number of bytes currently in the input buffer
  GD> would do the trick.

  GD> What I really need is a sysread that fails if a specified string
  GD> is not read within a specified time.  i.e.  read_with_timeout(
  GD> file_handle, string_to_detect, timeout );

look up 4 arg select. or IO::Select.pm or Event.pm.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: 10 Oct 2000 18:18:05 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: UNIX/PERL question
Message-Id: <slrn8u6nat.1s6.clay@panix3.panix.com>

On Tue, 10 Oct 2000 17:45:18 GMT, christophe.conseil@equifax.com 
<christophe.conseil@equifax.com> wrote:

>Just trying to understand the following:
>I have a perl test program:
>
>first line: #!/usr/local/bin/perl -w
>I made sure it is executable.
>
>Now when I type test file1>file2 no error but nothing is written
>to file 2.

Do you have anything past the first line of your program?

-- 
Clay Irving <clay@panix.com>
Oh look, my brain just exploded! Cool idea, though. 
- Carl Rigney 


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

Date: Tue, 10 Oct 2000 14:32:32 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: UNIX/PERL question
Message-Id: <Pine.GSO.4.21.0010101430470.14163-100000@crusoe.crusoe.net>

[posted & mailed]

On Oct 10, christophe.conseil@equifax.com said:

>first line: #!/usr/local/bin/perl -w
>
>Now when I type test file1>file2 no error but nothing is written
>to file 2.
>
>On the otherhand: perl test file1>file2 works fine.

Don't name your program 'test'.  Unix has a command called 'test'.  It's
getting called, not your program.  Name your program something else.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: 10 Oct 2000 15:12:44 -0400
From: Doug Perham <dperham@dperham.eng.tvol.net>
Subject: Re: UNIX/PERL question
Message-Id: <81aecca4sz.fsf@wgate.com>

christophe.conseil@equifax.com writes:

> Hi guys:
> 
> Just trying to understand the following:
> I have a perl test program:
> 
> first line: #!/usr/local/bin/perl -w
> I made sure it is executable.
> 
> Now when I type test file1>file2 no error but nothing is written
> to file 2.
> 
> On the otherhand: perl test file1>file2 works fine.
> 
> I made sure of the following:
> typing "which perl" i get: /usr/local/bin/perl
> Also, I made sure that this path and also the . path are in my
> path variable, in my .cshrc file.
> 
> Any idea why it does not work the first way.
> 
> Thank you all for your time and help.
> 
> Christophe
> 
> 
> Sent via Deja.com http://www.deja.com/
> Before you buy.


there is also a UNIX command called 'test' (and many shells implement it
as an intrinsic function). it is this function that is getting called
instead of your perl script because it is your PATH first or it is
intrinsic in your shell.  try typing 

 ./test file1>file2 

by putting the explicit path, you avoid the ambiguity. otherwize you can
rename your perl script to 'ptest' or something like that.

fyi, type 

   which test

to find out which 'test' script you were truly executing

-- 
Doug Perham                                          o{..}o     
dperham@wgate.com                                moo! (oo)___   
WorldGate Communications, Inc.                        (______)\ 
                                                      / \  / \  


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

Date: Tue, 10 Oct 2000 21:30:27 GMT
From: billgerba@my-deja.com
Subject: Writing multple lines to a file at once?
Message-Id: <8s01pj$qrj$1@nnrp1.deja.com>

Hello,

I'm a newbie to the Perl world, but I'm finding that it really is by
far the best tool for the job (in this case, using a web-based
interface to write script files).  However, I was wondering if there
was a way to print multiple lines to a file at the same time.  For
example, I've been doing this for every line I print to a file:

open OUTFILE, ">$out" or die "Cannot open $out for write :$!";

print OUTFILE "something goes here";
print OUTFILE "something else goes here";
print OUTFILE "yet something else again goes here";

However, I would like to be able to print many lines at once to the
file, like I can to the console (or HTML) with:

print <<OUTFILE;
la dee da la dee da
la dee da la dee da
la dee da la dee da
la dee da la dee da
la dee da la dee da
OUTFILE

I haven't been able to figure out if there's a syntax that will let me
do this but send the output to some file $myFileName or something like
that.  Can it be done?

Thanks,

Bill


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 10 Oct 2000 14:43:53 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Writing multple lines to a file at once?
Message-Id: <39E38D99.25AEA41B@vpservices.com>

billgerba@my-deja.com wrote:
> 
> print <<OUTFILE;
> la dee da la dee da
> la dee da la dee da
> la dee da la dee da
> la dee da la dee da
> la dee da la dee da
> OUTFILE

Close, but no cigar.

What you want is:

print OUTFILE <<END_OF_PRINT_MARKER;
la dee da la dee da
la dee da la dee da
 ...
END_OF_PRINT_MARKER

-- 
Jeff


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

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


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