[17825] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5245 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 4 21:58:30 2001

Date: Thu, 4 Jan 2001 18:58:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <978663489-v9-i5245@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 4 Jan 2001     Volume: 9 Number: 5245

Today's topics:
        Reading Variables From File vimpaler24@my-deja.com
    Re: Reading Variables From File <jhelman@wsb.com>
    Re: Reading Variables From File (Garry Williams)
    Re: Reading Variables From File <jhelman@wsb.com>
    Re: Reading Variables From File vimpaler24@my-deja.com
    Re: Reading Variables From File <flavell@mail.cern.ch>
    Re: Reading Variables From File vimpaler24@my-deja.com
    Re: Reading Variables From File <jhelman@wsb.com>
    Re: Reading Variables From File (Tad McClellan)
    Re: Reading Variables From File vimpaler24@my-deja.com
    Re: Reading Variables From File <Hans.de.Bruin@chello.nl>
    Re: Reading Variables From File <tzz@heechee.beld.net>
    Re: Reading Variables From File vimpaler24@my-deja.com
        Realy strange database entry problem <gorgano@altavista.com>
        regex question tunneling@my-deja.com
    Re: regex question (Steven Smolinski)
        Regexp for balanced parens (Victor Eijkhout)
    Re: Regexp for balanced parens (Tad McClellan)
    Re: Regexp for balanced parens (Victor Eijkhout)
    Re: Regexp for balanced parens <mischief@velma.motion.net>
    Re: Regexp for balanced parens nobull@mail.com
    Re: Regexp for balanced parens <bart.lateur@skynet.be>
    Re: Regexp for balanced parens (Craig Kelly)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sat, 30 Dec 2000 15:50:51 GMT
From: vimpaler24@my-deja.com
Subject: Reading Variables From File
Message-Id: <92l08p$e7b$1@nnrp1.deja.com>

I am trying to read in some variables from a file, I would like to
define the variable and then import the file and change the variables,
I have tried it two ways, and haven't gotten it to work with either.

1.
Default.cfg
-----------
LogFile = logfile.log

test.pl
-------
#!/usr/bin/perl -w
use strict;
no strict 'refs';

my @tmpArray;
my $refVariable;
my $ConfigFile = "default.cfg";
my $LogFile = "default.log";

open(CONFIG, );
while(<CONFIG>)
{
	@tmpArray = split(/ = /, $_);
	chomp($tmpArray[0]);
	chomp($tmpArray[1]);
	$refVariable = "$tmpArray[0]";
	$$refVariable = "$tmpArray[1]";
}

print "$LogFile";

This one prints out fine, but it will print default.log, instead of
logfile.log like I want it to.

2.
Default.cfg
-----------
$LogFile = "logfile.log";

test.pl
-------
#!/usr/bin/perl -w
use strict;

my $ConfigFile = "default.cfg";
my $LogFile = "default.log";

require $ConfigFile;

this one does pretty much the same thing.


I like the way 1 works, since users don't have to worry about perl
syntax.

Thanks for anything you might be able to add.

Vlad (Chris)
cpickett@c21rg.net
ICQ: 63246594


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


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

Date: Sat, 30 Dec 2000 16:26:13 GMT
From: Jeff Helman <jhelman@wsb.com>
Subject: Re: Reading Variables From File
Message-Id: <fs2s4to47rpomudefbedfteuhp6uf0d9il@4ax.com>

On Sat, 30 Dec 2000 15:50:51 GMT, vimpaler24@my-deja.com wrote:

>#!/usr/bin/perl -w
>use strict;
>no strict 'refs';
>
>my @tmpArray;
>my $refVariable;
>my $ConfigFile = "default.cfg";
>my $LogFile = "default.log";
>
>open(CONFIG, );

Well, here's one problem.  What are you opening?  If you had checked
the return value of this system call, you'd know that this open()
failed.  Fix it as such:

open(CONFIG, $ConfigFile) or die "Couldn't open file: $!";

>while(<CONFIG>)
>{
>	@tmpArray = split(/ = /, $_);
>	chomp($tmpArray[0]);
>	chomp($tmpArray[1]);
>	$refVariable = "$tmpArray[0]";
>	$$refVariable = "$tmpArray[1]";
>}

This loop was skipped since the open call failed (and thus, you don't
have anything on this filehandle to read).

>print "$LogFile";
>
>This one prints out fine, but it will print default.log, instead of
>logfile.log like I want it to.

What do you expect it to print?  You defined variable $LogFile at the
top of your script and then you never modified it.  Thus, it prints
your original value.

Fix your open() call and that will fix your problem.

JH



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

Date: Sat, 30 Dec 2000 17:08:27 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Reading Variables From File
Message-Id: <fEo36.21$zp4.2688@eagle.america.net>

On Sat, 30 Dec 2000 16:26:13 GMT, Jeff Helman <jhelman@wsb.com> wrote:
>On Sat, 30 Dec 2000 15:50:51 GMT, vimpaler24@my-deja.com wrote:

> ... If you had checked
>the return value of this system call, you'd know that this open()
>failed.  Fix it as such:
>
>open(CONFIG, $ConfigFile) or die "Couldn't open file: $!";

Don't you just love those error messages that tell about a file
problem without identifying the file name (or path)?  

-- 
Garry Williams


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

Date: Sat, 30 Dec 2000 17:21:31 GMT
From: Jeff Helman <jhelman@wsb.com>
Subject: Re: Reading Variables From File
Message-Id: <cb6s4t46hvm145ph7ssnmod7k17uvn7qj3@4ax.com>

On Sat, 30 Dec 2000 17:08:27 GMT, garry@zvolve.com (Garry Williams)
wrote:

>> ... If you had checked
>>the return value of this system call, you'd know that this open()
>>failed.  Fix it as such:
>>
>>open(CONFIG, $ConfigFile) or die "Couldn't open file: $!";
>
>Don't you just love those error messages that tell about a file
>problem without identifying the file name (or path)?  

Oops.  I had originally written that line without the $ConfigFile
piece (and since there was no file name or path supplied, including it
in the error message would have been difficult at best).  I stand
corrected.

JH


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

Date: Sat, 30 Dec 2000 19:14:59 GMT
From: vimpaler24@my-deja.com
Subject: Re: Reading Variables From File
Message-Id: <92lc7f$n1l$1@nnrp1.deja.com>

In article <fs2s4to47rpomudefbedfteuhp6uf0d9il@4ax.com>,
  Jeff Helman <jhelman@wsb.com> wrote:
> On Sat, 30 Dec 2000 15:50:51 GMT, vimpaler24@my-deja.com wrote:
>
> >#!/usr/bin/perl -w
> >use strict;
> >no strict 'refs';
> >
> >my @tmpArray;
> >my $refVariable;
> >my $ConfigFile = "default.cfg";
> >my $LogFile = "default.log";
> >
> >open(CONFIG, );
>
> Well, here's one problem.  What are you opening?  If you had checked
> the return value of this system call, you'd know that this open()
> failed.  Fix it as such:
>
Ya, I have it like, open(CONFIG, $ConfigFile)

i just messed up when I type it into here, I did add the or die part,
but it does open, and did.

> open(CONFIG, $ConfigFile) or die "Couldn't open file: $!";
>
> >while(<CONFIG>)
> >{
> >	@tmpArray = split(/ = /, $_);
> >	chomp($tmpArray[0]);
> >	chomp($tmpArray[1]);
> >	$refVariable = "$tmpArray[0]";
> >	$$refVariable = "$tmpArray[1]";
> >}
>
> This loop was skipped since the open call failed (and thus, you don't
> have anything on this filehandle to read).
>
> >print "$LogFile";
> >
> >This one prints out fine, but it will print default.log, instead of
> >logfile.log like I want it to.
>
> What do you expect it to print?  You defined variable $LogFile at the
> top of your script and then you never modified it.  Thus, it prints
> your original value.
>
> Fix your open() call and that will fix your problem.
>
> JH
>
>


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


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

Date: Sat, 30 Dec 2000 20:50:09 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Reading Variables From File
Message-Id: <Pine.LNX.4.30.0012302036040.5630-100000@lxplus003.cern.ch>

On Sat, 30 Dec 2000 vimpaler24@my-deja.com wrote:

[much pointless quotage]

> i just messed up when I type it into here,

Then that's your problem.  Don't ever retype code into here, or you'll
find yourself landing in lots of killfiles.

> I did add the or die part, but it does open, and did.

Then you've been wasting the group's time.  In your own interests, I'd
recommend that you show the other hon. Unenauts that you understand
your mistake, and are going to take care not to make it again. I seem
to recall a proto-FAQ posted rather recently, that covered these
issues rather well.

In brief: always copy/paste your actual problem code into the posting.
If it's too complex or contains a lot of irrelevances, then boil it
down to a simple, but complete and runnable, example that genuinely
demonstrates the problem you were having (while doing that you'll
often solve your problem for yourself).

Then (if still necessary) copy/paste your actual sample code into your
posting, showing what it did and what you had expected/wanted it to
do.

[more futile quotage removed.  Learn to trim your quotage to the
minimum relevant.]

This group can be genuinely helpful to those who show some sign of
being willing to work with it.  I know it has been for me, and it
infuriates me when I see people pointlessly wasting the group's time
and effort.  There's nothing wrong - provided one's willing to pay
a bit of attention to what's going on, and co-operate with the
group's preferred way of doing business - with being a beginner or
with making genuine mistakes.  But what you seem to have been doing
didn't seem to qualify as either of those things.

good luck



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

Date: Sat, 30 Dec 2000 20:49:40 GMT
From: vimpaler24@my-deja.com
Subject: Re: Reading Variables From File
Message-Id: <92lhp2$ra1$1@nnrp1.deja.com>


>Then you've been wasting the group's time.  In your own interests, I'd
>recommend that you show the other hon. Unenauts that you understand
>your mistake, and are going to take care not to make it again. I seem
>to recall a proto-FAQ posted rather recently, that covered these
>issues rather well.

>In brief: always copy/paste your actual problem code into the posting.
>If it's too complex or contains a lot of irrelevances, then boil it
>down to a simple, but complete and runnable, example that
>genuinely .demonstrates the problem you were having (while doing that
>you'll often solve your problem for yourself).

>Then (if still necessary) copy/paste your actual sample code into your
>posting, showing what it did and what you had expected/wanted it to do.
>This group can be genuinely helpful to those who show some sign of
>being willing to work with it.  I know it has been for me, and it
>infuriates me when I see people pointlessly wasting the group's time
>and effort.  There's nothing wrong - provided one's willing to pay a
>bit of attention to what's going on, and co-operate with the
>group's preferred way of doing business - with being a beginner or
>with making genuine mistakes.  But what you seem to have been doing
>didn't seem to qualify as either of those things.

>good luck

How have I wasted the groups time?
The code still does not work, and that is the only line I type in,
which I suppose is why it is the one that is messed up, I did boil the
code down, the actual file is about 250 lines, most of it pointless to
the topic at hand, it IMO is a good topic, I would like to know how to
do it, I have almost the whole O'Reily series of books on perl, but
none of the ones I have really cover this topic.

I apologize for the amount of quotage, didn't realize there was that
much, and I normally do.


Just allow me to say that your post is the main reason I
absolutely hate Newsgroups, your post had nothing but "trim your
quoteage, and you wasted this boards time". No actual help to the
problem at hand. You are cluttering this board up with your worthless
posts, if some of you people would stay on topic, and try and help a
little more, I think this would be a much better place. I am sure I
could find a couple hundred posts that are just like yours if I wanted
to, which also IMO is a bigger waste of space than almost any other
type of thread next to a flame. All I was doing in my post was trying
to get my actual quertsion understood, and answered, if this is against
the newsgroups policy, then I don't think I want to be part of it.

Vlad


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


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

Date: Sat, 30 Dec 2000 21:34:13 GMT
From: Jeff Helman <jhelman@wsb.com>
Subject: Re: Reading Variables From File
Message-Id: <svks4t0n5t0eg0nminmuoaj1q9q8ql1ko9@4ax.com>

On Sat, 30 Dec 2000 20:49:40 GMT, vimpaler24@my-deja.com wrote:

>How have I wasted the groups time?

In two ways.  First, you posted code that did not demonstrate the
problem as written.  As I read your code the error in the open jumped
out at me.  Since your loop would never execute, I didn't pay a whole
lot of attention to it.

>The code still does not work.

This is the second way you have wasted our time.  Had you bothered to
check the FAQs, particularly the entry titled "How can I use a
variable as a variable name?" in perlfaq7, you would have seen the
following text...

"The first reason is that they only work on global variables. That
means above that if $fred is a lexical variable created
with my(), that the code won't work at all: you'll accidentally access
the global and skip right over the private lexical
altogether. Global variables are bad because they can easily collide
accidentally and in general make for non-scalable
and confusing code."

This explains why your code doesn't work.  Incidentally, this entry
also explains why what you are trying to do is a bad idea.  I'd
recommend reading it.

JH


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

Date: Sat, 30 Dec 2000 14:39:00 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Reading Variables From File
Message-Id: <slrn94seek.4av.tadmc@magna.metronet.com>

vimpaler24@my-deja.com <vimpaler24@my-deja.com> wrote:

[ vimpaler24 said earlier that he retyped code into his post
  rather than include his real code.
]


Some unattributed person wrote (but who said it
was not included in vimpaler24's followup for some reason):

>>Then you've been wasting the group's time.

>>In brief: always copy/paste your actual problem code into the posting.


>How have I wasted the groups time?


By asking them to debug code that does not exist!


>I would like to know how to
>do it, 


It looks like "it" involves symbolic references.

Friends don't let friends use symrefs:

   http://www.plover.com/~mjd/perl/varvarname.html
   http://www.plover.com/~mjd/perl/varvarname2.html
   http://www.plover.com/~mjd/perl/varvarname3.html

>I have almost the whole O'Reily series of books on perl, but
>none of the ones I have really cover this topic.


Because symrefs are evil, not telling you about them is
the best thing for you.


>Just allow me to say that your post is the main reason I
>absolutely hate Newsgroups, your post had nothing but "trim your
>quoteage, and you wasted this boards time". 


But you did not trim and you did waste time (and this is not
a "board", this is a Usenet newsgroup).


>No actual help to the
>problem at hand. You are cluttering this board up with your worthless
>posts, if some of you people would stay on topic, and try and help a
>little more, I think this would be a much better place.


Well now you have gone and made "the mystery person quoted above"'s 
prediction come true. 

Wasting the groups time didn't get you killfiled. Quoting 50
lines and adding 2 lines didn't get you killfiled. Using
evil symbolic references didn't get you killfiled.

Whining got you killfiled.

So long.


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


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

Date: Sat, 30 Dec 2000 22:37:17 GMT
From: vimpaler24@my-deja.com
Subject: Re: Reading Variables From File
Message-Id: <92lo2t$3g$1@nnrp1.deja.com>

I did originally get some of the code from an O'Reily book, Perl
Programming, but it never mentioned how to set one that has already
been set, second, I had no idea there was such an FAQ.

You are just a bunch of Holier than thou fuckwits. I'll do it on my
own, thank you for letting me waste your time with such a useless post,
since I am sure you have better things to do like flame someone, or
correct their spelling.


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


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

Date: Sun, 31 Dec 2000 13:33:00 GMT
From: "Hans de Bruin" <Hans.de.Bruin@chello.nl>
Subject: Re: Reading Variables From File
Message-Id: <gAG36.306689$%C1.3760901@Flipper>


<vimpaler24@my-deja.com> wrote in message
news:92l08p$e7b$1@nnrp1.deja.com...
> I am trying to read in some variables from a file, I would like to
 ...
> my $LogFile = "default.log";
>
> open(CONFIG, );
> while(<CONFIG>)
> {
> @tmpArray = split(/ = /, $_);
> chomp($tmpArray[0]);
> chomp($tmpArray[1]);
> $refVariable = "$tmpArray[0]";
> $$refVariable = "$tmpArray[1]";
> }
>
> print "$LogFile";
>

Your open() problem should be solved bij now. Why dont you use to regex to
do the job, like:

while(<CONFIG>)
{
  if (/^\s*([a-z]\w*)\s*=\s*(.+)/i)
  {
    $$1=$2;
  }
}
print $myvar;

or maybe even better include de cfg file with require like:

#!perl
require "default.cfg";

with default.cfg containes

#!perl
#
# $logfile : name of the logfile
$LogFile = logfile.log





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

Date: 01 Jan 2001 11:49:31 -0500
From: Ted Zlatanov <tzz@heechee.beld.net>
Subject: Re: Reading Variables From File
Message-Id: <m3wvcfdxpg.fsf@heechee.beld.net>

vimpaler24@my-deja.com writes:

> I did originally get some of the code from an O'Reily book, Perl
> Programming, but it never mentioned how to set one that has already
> been set, second, I had no idea there was such an FAQ.

You really should lurk for a while before posting.  It's good for your
health.  FAQs get posted periodically, and you can also read them with
"perldoc perlfaq" from the command line on your own system.

One of the solutions to your original problem is to use the AppConfig
module from CPAN (http://www.cpan.org).  You can do a preliminary scan
of the file, if you don't know what variable names you are expecting
(you need to define variables before reading the config file with
AppConfig).

> You are just a bunch of Holier than thou fuckwits. I'll do it on my
> own, thank you for letting me waste your time with such a useless post,
> since I am sure you have better things to do like flame someone, or
> correct their spelling.

You're being rude to people who are trying to help you.

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


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


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

Date: Wed, 03 Jan 2001 04:44:29 GMT
From: vimpaler24@my-deja.com
Subject: Re: Reading Variables From File
Message-Id: <92uand$95c$1@nnrp1.deja.com>

In article <m3wvcfdxpg.fsf@heechee.beld.net>,
  Ted Zlatanov <tzz@heechee.beld.net> wrote:

> You're being rude to people who are trying to help you.

They were rude to me first, and I didn't see much help coming out of
that, the only help I was getting was, your wasting our time, don't
quote so much. But I do thank you, Hans de Bruin & partly  Tad
McClellan for the help, I have it working now, I will lurk from now on,
and try and catch the FAQ's. I am sorry for being a jerk, but I don't
let people talk to me like that in real life or not.

Vlad


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


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

Date: Tue, 02 Jan 2001 23:15:25 GMT
From: Jason Hurst <gorgano@altavista.com>
Subject: Realy strange database entry problem
Message-Id: <92tne6$p7u$1@nnrp1.deja.com>

I’ve got a pretty simple program which takes a directory name as an
argument and then scans that directory, recording all the documents
information there in, in a database.
As you can see from the code (bellow) it first queries the database to
see what the next ‘id’ number is, then increments that before adding
the next value.  Now, for some reason when there are 10 items in the
database it will pull ‘1’, and then increment it to ‘2’.  Which then
throws an error saying ‘2 is already and index’.  It also does this on
100, returning 11.  The only thing I can think of is it is hacking off
the last digit before it increments.  But I can’t figure how why it
does it only on those two numbers.  Can someone please take a look at
the code, I’m sure its something simple that I’m just over looking.
The code and the codes output are bellow.  Thanks in advance for your
help.

-jason


Here is the code:

#!c:/progra~1/perl/bin/perl.exe

use DBI;
print "content-type:text/html\n\n";

  ##########Do some simple sql stuff#########
  #####Lets do our db connect#####
  $dbh = DBI->connect('dbi:ODBC:intranetGroupDB') or &HTMLdie
("Connection failed: $DBI::errstr\n");
  $dbh->{LongReadLen}=19999;
  $dbh->{LongTruncOk}=1;
  ######

  #prepare statment for getting the max id
  $getID = $dbh->prepare("select max(id) from documentStore;");

  #prepare statment for inserting a document for directory
  $putFile = $dbh->prepare("insert into documentStore
      		(id, name, type, path, directoryLink, directoryIn,
description, size, owner, lastMod, groupID)
		values
		(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
  #################done###############

  $curr_dir="c:/mydocu~1/";

  #Open the current directory
  opendir (DIR, $curr_dir) || &HTMLdie("can't open $directory: $! --
$curr_dir --");

  #Look though that directory and see if we have any files to parse
  while ($_ = readdir (DIR))
  {
print "$_\n";
    my $entry = $curr_dir . "/" . $_;
    my ($filePath,$fileUrl,$time,$size,$id);

    if (/^\.*$/) { next; }
    elsif (-f $entry) {
      #if a file, then copy it to the document store
      # and add it to the database

      #get the next id
      $getID->execute;
      ($id) = $getID->fetchrow_array;
      $getID->finish;
      ++$id;

      #add to the database
      print qq($id, $_, $sufix, $fileUrl, '0', $DsGroupNumber, '',
$size, $username, $time, $sGroup<br>);
      $putFile->execute($id, $_, $sufix, $fileUrl, '0',
$DsGroupNumber, '', $size, $username, $time, $sGroup) or print
$DBI::errstr;
      $putFile->finish;
    }
  }


here is the output:

 .
 ..
cbt.html
2, cbt.html, , , '0', , '', , , , <br>desktop.ini
3, desktop.ini, , , '0', , '', , , , <br>eventcalendar-1.3.1.tar.gz
4, eventcalendar-1.3.1.tar.gz, , , '0', , '', , , ,
<br>slog.status.sub.txt
5, slog.status.sub.txt, , , '0', , '', , , ,
<br>printerfriendly.jhtmlidr00620001024aue01.htm.html
6,
printerfriendly.jhtmlidr00620001024aue01.htm.html, , , '0', , '', , , ,
<br>addbook-1.0.tar.gz
7, addbook-1.0.tar.gz, , , '0', , '', , , , <br>exploit.txt
8, exploit.txt, , , '0', , '', , , , <br>RMB-
We_just_need_more_Ecstasy.mp3
9, RMB-We_just_need_more_Ecstasy.mp3, , , '0', , '', , , ,
<br>intranet.ZIP
10, intranet.ZIP, , , '0', , '', , , , <br>jac.zip
2 , jac.zip, , , '0', , '', , , , <br>[TCX][MyODBC]Duplicate entry '2'
for key 1 (SQL-S1000)
[TCX][MyODBC]Data truncated (SQL-01004)(DBD: st_execute/SQLExecute err=-
1)temp
Revenue Plus Web Site RFP-Gregs Version.doc
2 , Revenue Plus Web Site RFP-Gregs Version.doc, , , '0', , '', , , ,
<br>[TCX][MyODBC]Duplicate entry '2' for key 1 (SQL-S1000)
[TCX][MyODBC]Data truncated (SQL-01004)(DBD: st_execute/SQLExecute err=-
1)backup
My Pictures
GrungeX1.gif
2 , GrungeX1.gif, , , '0', , '', , , , <br>[TCX][MyODBC]Duplicate
entry '2' for key 1 (SQL-S1000)
[TCX][MyODBC]Data truncated (SQL-01004)(DBD: st_execute/SQLExecute err=-
1)mod_perl_activestate.txt
2 , mod_perl_activestate.txt, , , '0', , '', , , , <br>[TCX][MyODBC]
Duplicate entry '2' for key 1 (SQL-S1000)
[TCX][MyODBC]Data truncated (SQL-01004)(DBD: st_execute/SQLExecute err=-
1)ssl
marketing.txt
2 , marketing.txt, , , '0', , '', , , , <br>[TCX][MyODBC]Duplicate
entry '2' for key 1 (SQL-S1000)
[TCX][MyODBC]Data truncated (SQL-01004)(DBD: st_execute/SQLExecute err=-
1)test.pl
2 , test.pl, , , '0', , '', , , , <br>[TCX][MyODBC]Duplicate entry '2'
for key 1 (SQL-S1000)
[TCX][MyODBC]Data truncated (SQL-01004)(DBD: st_execute/SQLExecute err=-
1)test.txt
2 , test.txt, , , '0', , '', , , , <br>[TCX][MyODBC]Duplicate entry '2'
for key 1 (SQL-S1000)
[TCX][MyODBC]Data truncated (SQL-01004)(DBD: st_execute/SQLExecute err=-
1)cbt
flash



Thanks again for your help!



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


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

Date: Tue, 02 Jan 2001 22:16:00 GMT
From: tunneling@my-deja.com
Subject: regex question
Message-Id: <92tjuo$m4f$1@nnrp1.deja.com>

A working search and replace expression is:
$_ =~ s/today\=(\S*)1/today\=$1 2/ig ;

A sample subject file is:
today=tx1
today=t1
sssssssssss=tx1

I get the results:
today=tx 2
today=t 2
sssssssssss=tx1

I desire the results:
today=tx2
today=t2
sssssssssss=tx1

I cannot figure out how to get around the
whitespace between $1 and 2, if I move the 2 next
to the $1 is looks for the 12th buffered search
expression, which obviously does not exist.

Tunneling


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


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

Date: Tue, 02 Jan 2001 22:55:36 GMT
From: sjs@linux.ca (Steven Smolinski)
Subject: Re: regex question
Message-Id: <slrn954r5o.ko.sjs@ragnar.stevens.gulch>

tunneling@my-deja.com <tunneling@my-deja.com> wrote:
> A working search and replace expression is:
> $_ =~ s/today\=(\S*)1/today\=$1 2/ig ;

The "$_ =~" part is redundant.  // operates on $_ be default.

> A sample subject file is:
> today=tx1
> today=t1
> sssssssssss=tx1
> 
> I get the results:
> today=tx 2
> today=t 2
> sssssssssss=tx1
> 
> I desire the results:
> today=tx2
> today=t2
> sssssssssss=tx1
> 
> I cannot figure out how to get around the
> whitespace between $1 and 2, if I move the 2 next
> to the $1 is looks for the 12th buffered search
> expression, which obviously does not exist.

The ${varname} construct disambiguates your variable name from
surrounding context.  See below.

#!/usr/local/bin/perl

use warnings;
use strict;

while ( <DATA> ) {
        s/today\=(\S*)1/today\=${1}2/ig;
        print;
}

__DATA__
today=tx1
today=t1
sssssssssss=tx1 

output ==> 

today=tx2
today=t2
sssssssssss=tx1


Steve
-- 
Steven Smolinski => http://www.steven.cx/


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

Date: Fri, 29 Dec 2000 08:59:07 -0500
From: victor@eijkhout.net (Victor Eijkhout)
Subject: Regexp for balanced parens
Message-Id: <1eme853.waq1i51ta0vbmN%victor@eijkhout.net>

Basically I'm writing something like a Fortran compiler. In Perl. Yes, I
know. 

Anyway, given that I'm standing at the open parenthesis of an array
index, I can write the code to find the closing paren. But is it
possible do it with a regexp?

So, given "x(1,f(a(b),c))" I want to catch the whole indexing expression
"1,f(a(b),c)" in a pattern match.  

-- 
Victor Eijkhout
"the time comes for everyone to do deliberately what 
he used to do by mistake"  [Quentin Crisp]


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

Date: Fri, 29 Dec 2000 08:50:31 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Regexp for balanced parens
Message-Id: <slrn94p5l7.jsm.tadmc@magna.metronet.com>

Victor Eijkhout <victor@eijkhout.net> wrote:

>Subject: Regexp for balanced parens
                     ^^^^^^^^

   perldoc -q balanced

      "Can I use Perl regular expressions to match balanced text?"


You are expected to check the Perl FAQs *before* posting to the
Perl newsgroup.


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


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

Date: Fri, 29 Dec 2000 11:33:53 -0500
From: victor@eijkhout.net (Victor Eijkhout)
Subject: Re: Regexp for balanced parens
Message-Id: <1emefr7.fxu6ex1qwrxveN%victor@eijkhout.net>

Tad McClellan <tadmc@metronet.com> wrote:

> You are expected to check the Perl FAQs *before* posting to the
> Perl newsgroup.

Well, I had just read that post about "where to find the FAQ", so I
follow the links:
http://www.cpan.org/doc/FAQs/
http://www.cpan.org/doc/manual/html/index.html
http://www.cpan.org/doc/manual/html/pod/perl.html

No search facility, seach for "balanced" doesn't turn up anything.

Backtrack:
http://www.cpan.org/doc/manual/html/pod/index.html

Ditto: no and no.

Backtrack (this one is even called FAQ):
http://www.cpan.org/doc/manual/html/pod/perlfaq.html

Ditto: no and no.

Now I start following serial links:
http://www.cpan.org/doc/manual/html/pod/perlfaq1.html - ditto
http://www.cpan.org/doc/manual/html/pod/perlfaq6.html

Ah. There it is. I'm so sorry for overlooking the obvious :-)

Seriously, I didn't know about the "-q" option. I did read all the man
pages about regexps.



-- 
Victor Eijkhout
"the time comes for everyone to do deliberately what 
he used to do by mistake"  [Quentin Crisp]


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

Date: Fri, 29 Dec 2000 17:49:15 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Regexp for balanced parens
Message-Id: <t4pjkr3unp09cd@corp.supernews.com>

Victor Eijkhout <victor@eijkhout.net> wrote:
> Basically I'm writing something like a Fortran compiler. In Perl. Yes, I
> know. 

I haven't done it for Fortran, but I've done syntax checkers, source
reformatters, string extractors, and other miscellaneous source-code
tools for C, Perl, and a few little languages in Perl. I even wrote
a full translator (to C) for a my own little language used as a
world description interface for a MUD style game. So I have an idea
what you are facing.


> Anyway, given that I'm standing at the open parenthesis of an array
> index, I can write the code to find the closing paren. But is it
> possible do it with a regexp?

Even if possible, I'd reccommend not doing that. Lexing and parsing
are much more flexible than a regex. You can tweak a lexer and
parser much more readily. There are even versions of yacc that
create Perl output.

> So, given "x(1,f(a(b),c))" I want to catch the whole indexing expression
> "1,f(a(b),c)" in a pattern match.  

Don't do that. ;)

It may be possible, but it's not a good idea IMHO.

Chris

-- 
Christopher E. Stith

Even in the worst of times, there is always someone who's never had it better.
Even in the best of times, there is always someone who's never had it worse.



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

Date: 29 Dec 2000 17:46:47 +0000
From: nobull@mail.com
Subject: Re: Regexp for balanced parens
Message-Id: <u9wvcj3yt4.fsf@wcl-l.bham.ac.uk>

victor@eijkhout.net (Victor Eijkhout) writes:

> Subject: Regexp for balanced parens

FAQ: Can I use Perl regular expressions to match balanced text?

Please read the FAQ _before_ you post.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 29 Dec 2000 23:03:30 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Regexp for balanced parens
Message-Id: <fk5q4ts0j3rh8lmcfe1uv3763ggq0dg60l@4ax.com>

Victor Eijkhout wrote:

>Basically I'm writing something like a Fortran compiler. In Perl. Yes, I
>know. 
>
>Anyway, given that I'm standing at the open parenthesis of an array
>index, I can write the code to find the closing paren. But is it
>possible do it with a regexp?
>
>So, given "x(1,f(a(b),c))" I want to catch the whole indexing expression
>"1,f(a(b),c)" in a pattern match.  

I wouldn't do it in that way. I'd check out CPAN, and fetch the module
Text::Balanced. It is part of the Parse::RecDescent distribution.
(Apparently, it's available separately as well.) Ooh, mabe you can
simply write a BNF for Fortran, and use Parse::RecDescent to create a
parser for it.

	<http://search.cpan.org/search?dist=Parse-RecDescent>
	<http://search.cpan.org/search?dist=Text-Balanced>


BTW, there also is a BASIC interpreter, in Perl, available on CPAN. That
could serve as an example for what you're trying to achieve. I haven't
actually checked it out.

	<http://search.cpan.org/search?dist=Language-Basic>

-- 
	Bart.


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

Date: Mon, 01 Jan 2001 15:05:38 GMT
From: cekellySpam.this@dvol.com (Craig Kelly)
Subject: Re: Regexp for balanced parens
Message-Id: <3a509c12.422827574@news.dvol.com>

On Fri, 29 Dec 2000 11:33:53 -0500, victor@eijkhout.net (Victor
Eijkhout) wrote:

>Tad McClellan <tadmc@metronet.com> wrote:
>
>> You are expected to check the Perl FAQs *before* posting to the
>> Perl newsgroup.
>
>Well, I had just read that post about "where to find the FAQ", so I
>follow the links:
>http://www.cpan.org/doc/FAQs/
>http://www.cpan.org/doc/manual/html/index.html
>http://www.cpan.org/doc/manual/html/pod/perl.html
>
>No search facility, seach for "balanced" doesn't turn up anything.
>
Well, I typed this on my W95 box (Activestate build 520):
D:\>perldoc -q balanced
Found in C:\perl\lib\pod\perlfaq6.pod
  Can I use Perl regular expressions to match balanced text?

            Although Perl regular expressions are more powerful than
            "mathematical" regular expressions, because they feature
            conveniences like backreferences (`\1' and its ilk),
            they still aren't powerful enough. You still need to use
            non-regexp techniques to parse balanced text, such as
            the text enclosed between matching parentheses or
            braces, for example.

            An elaborate subroutine (for 7-bit ASCII only) to pull
            out balanced and possibly nested single chars, like ``'
            and `'', `{' and `}', or `(' and `)' can be found in
            http://www.perl.com/CPAN/authors/id/TOMC/scripts/pull_qu
            otes.gz .

            The C::Scan module from CPAN contains such subs for
            internal usage, but they are undocumented.

Craig Kelly <cekelly@dvol.com>
-------------------------------
"Hey, I'm just this guy, see?"
            -Zaphod Beeblebrox
-------------------------------


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

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


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