[31569] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2828 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Feb 21 11:09:25 2010

Date: Sun, 21 Feb 2010 08:09:08 -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           Sun, 21 Feb 2010     Volume: 11 Number: 2828

Today's topics:
    Re: a defense of ad hoc software development <rNOSPAMon@flownet.com>
        Call for papers: SETP-10, Orlando, USA, July 2010 (jmheralds)
    Re: How to do variable-width look-behind? sln@netherlands.com
    Re: One-Liner Mania <usenet@larseighner.com>
    Re: One-Liner Mania <marc.girod@gmail.com>
        perl advanced question <robin1@cnsp.com>
    Re: perl advanced question <ben@morrow.me.uk>
        Using eval to iterate over a set of Perl variables <news@lawshouse.org>
    Re: Using eval to iterate over a set of Perl variables <rvtol+usenet@xs4all.nl>
    Re: Using eval to iterate over a set of Perl variables <news@lawshouse.org>
    Re: Using eval to iterate over a set of Perl variables <rvtol+usenet@xs4all.nl>
    Re: Using eval to iterate over a set of Perl variables <tadmc@seesig.invalid>
    Re: Using eval to iterate over a set of Perl variables <source@netcom.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 20 Feb 2010 23:47:31 -0800
From: Ron Garret <rNOSPAMon@flownet.com>
Subject: Re: a defense of ad hoc software development
Message-Id: <rNOSPAMon-C0A9F7.23470120022010@news.albasani.net>

In article <slrnho06o8.g8e.hjp-usenet2@hrunkner.hjp.at>,
 "Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:

> > The issue PG was addressing (and that this thread seems to be about) is 
> > the perennial debate about how specific a HOW spec should be before you 
> > make your first attempt to render it into a form that is suitable as 
> > input to a compiler.  The right answer has a lot to do with how 
> > expensive it is to run your compiler.  If compilation is expensive it 
> > makes sense to put more effort into making sure you've thought things 
> > through before you try to compile.  If compilation (and more to the 
> > point, recompilation) is cheap then it makes less sense.
> 
> Compilation time is only one factor in this. You also need to consider
> the cost of testing, the cost of rewriting code, the cost of changing
> interfaces, the cost of missing deadlines, etc.

All true.  If any of these are expensive it makes more sense to do more 
design up front.

> And most importantly it misses the fact that the development of your HOW
> spec doesn't stop when "you make your first attempt to render it into a
> form that is suitable as input to a compiler", and the development of
> your WHAT spec doesn't stop when you start developing your HOW spec.
> Users often have only a very vague notion of what they need and they
> have poor imagination and abstraction facilities. When you show them
> your first prototype they will tell you that they wanted something
> completely different.

Yep.

> > Then there is the completely orthogonal issue of how to render WHAT 
> > specs into HOW specs, which is a fundamentally difficult problem.  It 
> > has to be.  If it weren't you could just take the following WHAT spec:
> >
> > * A program that takes a WHAT spec and renders it as a HOW spec
> 
> That's not a WHAT spec. It neither specifies the input nor the output.

Sure it does.  The input is a WHAT spec.  The output is a HOW spec.  I 
haven't gone into detail about what WHAT specs and HOW specs are and how 
they are represented, but I could.

> > and render *that* as a how spec and you'd never again have to write any 
> > code.
> 
> I think you missed my point: A formal WHAT spec *is* code.

I didn't miss that point, I just disagree with it.  There are lots of 
WHAT specs that are not and cannot be code.  The halting problem.  
Computing Chaitin's omega.  Even inverting SHA1 or factoring large RSA 
keys could be examples.

> So if you
> have that translator you just write code in your declarative WHAT
> language instead of your imperative HOW language. And as you write
> yourself:
> 
> 
> > In fact, just *writing down* a WHAT spec (let alone finding a 
> > corresponding HOW spec) is a fundamentally difficult problem.
> 
> So you may have solved the simpler part of the problem and be left with
> the harder part. (this is not true in all cases - obviously there are
> problems which are simple to describe and hard to solve, but in my
> experience most of the time the really hard part is the WHAT, not the
> HOW).

They can both be hard.

rg


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

Date: Sun, 21 Feb 2010 15:20:45 +0000
From: jmheralds_at_gmail_dot_com@foo.com (jmheralds)
Subject: Call for papers: SETP-10, Orlando, USA, July 2010
Message-Id: <79a25$4b814f4d$cf3aab60$16827@news.flashnewsgroups.com>

It would be highly appreciated if you could share this announcement with
your colleagues, students and individuals whose research is in software
engineering, software testing, software quality assurance, software design
and related areas.

Call for papers: SETP-10, Orlando, USA, July 2010

The 2010 International Conference on Software Engineering Theory and
Practice (SETP-10) (website: http://www.PromoteResearch.org ) will be held
during 12-14 of July 2010 in Orlando, FL, USA.  SETP is an important event
in the areas of Software development, maintenance, and other areas of
software engineering and related topics.

The conference will be held at the same time and location where several
other major international conferences will be taking place. The conference
will be held as part of 2010 multi-conference (MULTICONF-10). MULTICONF-10
will be held during July 12-14, 2010 in Orlando, Florida, USA. The primary
goal of MULTICONF is to promote research and developmental activities in
computer science, information technology, control engineering, and related
fields. Another goal is to promote the dissemination of research to a
multidisciplinary audience and to facilitate communication among
researchers, developers, practitioners in different fields. The following
conferences are planned to be organized as part of MULTICONF-10.

•	International Conference on Artificial Intelligence and Pattern
Recognition (AIPR-10)
•	 International Conference on Automation, Robotics and Control Systems
(ARCS-10)
•	International Conference on Bioinformatics, Computational Biology,
Genomics and Chemoinformatics (BCBGC-10)
•	International Conference on Computer Communications and Networks (CCN-10)
•	International Conference on Enterprise Information Systems and Web
Technologies (EISWT-10)
•	International Conference on High Performance Computing Systems (HPCS-10)
•	International Conference on Information Security and Privacy (ISP-10) 
•	International Conference on Image and Video Processing and Computer
Vision (IVPCV-10)
•	International Conference on Software Engineering Theory and Practice
(SETP-10) 
•	International Conference on Theoretical and Mathematical Foundations of
Computer Science (TMFCS-10) 

MULTICONF-10 will be held at Imperial Swan Hotel and Suites.  It is a
full-service resort that puts you in the middle of the fun! Located 1/2
block south of the famed International Drive, the hotel is just minutes
from great entertainment like Walt Disney Worldฎ Resort, Universal Studios
and Sea World Orlando. Guests can enjoy free scheduled transportation to
these theme parks, as well as spacious accommodations, outdoor pools and
on-site dining — all situated on 10 tropically landscaped acres. Here,
guests can experience a full-service resort with discount hotel pricing in
Orlando.


We invite draft paper submissions. Please see the website
http://www.PromoteResearch.org  for more details.

Sincerely
James Heralds





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

Date: Sat, 20 Feb 2010 21:45:10 -0800
From: sln@netherlands.com
Subject: Re: How to do variable-width look-behind?
Message-Id: <rvg1o5dm4ih1s3jlonscglj2ajsup44m75@4ax.com>

On Tue, 9 Feb 2010 15:23:34 -0800 (PST), "jl_post@hotmail.com" <jl_post@hotmail.com> wrote:

>Hi,
>
>   I have a Perl script that processes multi-line input.  The problem
>is, sometimes this input has newlines stuck in arbitrary places (such
>as right in the middle of a valid token).

If this is the case, that you have '\n' within arbitrary locations within
an otherwise valid token, then you have much bigger problems than worrying
about look behind.

So, I'm not sure what you mean by 'arbitrary locations'. I would have to
asume it could be anywhere.

So, your real problem is actually *framing* a valid token, not newlines.
Which is easier said than done. You would need some kind of analizer that
can distinguish a particular token pattern from other stream info, separate
them, clean them up, and put them back together.

Something like below might help. But, if your token stream is a little less
arbitrary, this could be reduced to something simpler.
I was just going to do/keep it for my own curiosity, but I thought I would post it
here anyway.

-sln
---------------

# tok_parse_nclean.pl
# -sln, 2/10
#
use strict;
use warnings;

my $input = qq(
 55N   
40E

N
5
1
 E42
N53 E44
  this is some other token text

N 5 and 38N11E more stuff 28N 99   E
  N5000 E4000
59N   
48E

56N 410   E
5000N4000 E
);

##
  my @tokens = ();
  my $new_input = '';
  my $digs = '\s*\d[\d\s]*';
  my $TOKenRegExp = qr/(?:\b(?:[NS]$digs[EW]$digs|$digs[NS]$digs[EW])\b)/;

##
  print "Input:\n",'-'x8,"\n";
  print $input,"\n";

##
  print "New Input:\n",'-'x8,"\n";

  while ($input =~ /( ($TOKenRegExp) | (?:(?!$TOKenRegExp)[^\n])+\n? )/xsg)
  {
	my $tok = $1;
	my $istok = defined $2;
	$tok =~ s/^\s*|\s*$//g;
	next if !length( $tok );

	if ($istok) {
		$tok =~ s/\n//g;
		$tok =~ s/(?<=\d)\s+(?=\d)//;
		$tok =~ s/^[NS]\K\s+(?=\d)//;
		$tok =~ s/\d\K\s+(?=[EW]$)//;
		$tok =~ s/\s+/ /g;
		push @tokens, $tok;
		$tok .= "\n";
	} else {
		$tok .= ' ';
	}
	$new_input .= $tok;
  }
  print $new_input,"\n";

##
  print "Found Tokens:\n",'-'x8,"\n";
  for (@tokens) {
	print "'$_'\n";
  }
  print '-'x8,"\n";

__END__

Input:
--------

 55N
40E

N
5
1
 E42
N53 E44
  this is some other token text

N 5 and 38N11E more stuff 28N 99   E
  N5000 E4000
59N
48E

56N 410   E
5000N4000 E

New Input:
--------
55N 40E
N51 E42
N53 E44
this is some other token text N 5 and 38N11E
more stuff 28N 99E
N5000 E4000
59N 48E
56N 410E
5000N4000E

Found Tokens:
--------
'55N 40E'
'N51 E42'
'N53 E44'
'38N11E'
'28N 99E'
'N5000 E4000'
'59N 48E'
'56N 410E'
'5000N4000E'
--------



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

Date: Sun, 21 Feb 2010 06:28:35 +0000 (UTC)
From: Lars Eighner <usenet@larseighner.com>
Subject: Re: One-Liner Mania
Message-Id: <slrnho1kjn.bvs.usenet@debranded.larseighner.com>

In our last episode, <269657-r571.ln1@osiris.mauzo.dyndns.org>, the lovely
and talented Ben Morrow broadcast on comp.lang.perl.misc:

> Quoth Lars Eighner <usenet@larseighner.com>:
>> Can I capture a group of digits, perform integer arithmetic on them,
>> and use them in the replacement?

> You want the /e switch.

Oh cool.  This seems fraught with possibilities.

>> Say I have a group of files named Fife_Ch01.html, Fife_Ch02.html
>> and so forth. The files all have a line with their own name.  I want
>> to replace the file name with the next number and do not care about
>> leading zeros.
>> 
>> So,
>> 
>> Fife_Ch01.html is replaced with 2
>> Fife_Ch02.html is replaced with 3
>>     and so forth.
>> 
>> Can I do this with a one-liner?
>> 
>> it would look something like this:
>> 
>> #perl -pi -e 's/Fife_Ch([0-9]*)\.html{a miracle happens}/\1/' Fife_Ch*.html

> Don't use \1 on the replacement side of s///. It was a sop to sed users

But ... but I *am* a sed user!  I want my sop!

Actually I mostly use one-liners in shell scripts.  I double-quote lots of
stuff and just hate escaping $s.

> put into perl 1 that has never been removed.

>     perl -pi -e's/Fife_Ch(\d*)\.html/$1 + 1/e' Fife_Ch*.html

-- 
  Lars Eighner <http://larseighner.com/>      Warbama's Afghaninam day: 81
            1949.4 hours since Warbama declared Viet Nam II.
     Warbama: An LBJ for the Twenty-First century.  No hope.  No change.


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

Date: Sun, 21 Feb 2010 03:02:55 -0800 (PST)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: One-Liner Mania
Message-Id: <b20e795c-a7f9-4e5e-b1ea-11cdf158b68f@f8g2000yqn.googlegroups.com>

On Feb 20, 11:52 pm, Ben Morrow <b...@morrow.me.uk> wrote:

> You want the /e switch.

I can see that I obviously missed the question,
focusing as I did on making sure that the single
string in the file I changed would be the one
matching the file name, and not even noticing
the issue of incrementing the number.

So, thanks for the /e switch which I didn't know.
Thanks also for the explanation about the .bak
files on cygwin.

Now, if the files also happen to contain the
names of other files in the list, these other
lines would be modified as well.
We were not told what else the files contain...
In fact, I assumed that the first (or an early)
line would contain the file name, but that there
could be lots of data below, which is why I
attempted to close the file after the
replacement, which with -pi, wasn't a good idea.

a> cat Fife_Ch3.html
Fife_Ch0.html
Fife_Ch1.html
Fife_Ch2.html
Fife_Ch3.html
a> perl -pi -e 's/^Fife_Ch(\d+)\.html$/$1 + 1/e if /^${ARGV}$/'
Fife_Ch*.html
a> rm *.bak
a> ls -l
total 12
-rw-r--r--+ 1 marc None    44 2010-02-21 10:40 Fife_Ch0.html
-rw-r--r--+ 1 marc None    44 2010-02-21 10:40 Fife_Ch1.html
-rw-r--r--+ 1 marc None    44 2010-02-21 10:40 Fife_Ch2.html
-rw-r--r--+ 1 marc None    44 2010-02-21 10:40 Fife_Ch3.html
a> cat Fife_Ch3.html
Fife_Ch0.html
Fife_Ch1.html
Fife_Ch2.html
4

Marc


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

Date: Sat, 20 Feb 2010 19:47:26 -0800 (PST)
From: Robin <robin1@cnsp.com>
Subject: perl advanced question
Message-Id: <5b5844a1-b028-4f1b-8822-54679d948139@z11g2000yqz.googlegroups.com>

Does anyone know how to start learning how to and or learn how to
start programming in perl a virus scanner or a firewall in perl?

Thanks,
-Robin


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

Date: Sun, 21 Feb 2010 12:43:18 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: perl advanced question
Message-Id: <6cm757-4fe1.ln1@osiris.mauzo.dyndns.org>


Quoth Robin <robin1@cnsp.com>:
> Does anyone know how to start learning how to and or learn how to
> start programming in perl a virus scanner or a firewall in perl?

It would be extremely difficult to write a firewall in Perl. You need to
get into the OS' network stack at a very low level, and that isn't easy
in Perl. A virus scanner basically just looks for known patterns in
files, but writing the scanner isn't the hard part: the hard part is
working out which patterns match viruses.

Ben



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

Date: Sun, 21 Feb 2010 13:27:50 +0000
From: Henry Law <news@lawshouse.org>
Subject: Using eval to iterate over a set of Perl variables
Message-Id: <RbKdncCPDqhpphzWnZ2dnUVZ8t6dnZ2d@giganews.com>

(I'm sure Google should have been able to help me with this but 
structuring a suitable query defeated me... a million hits or none.)

I'm inserting new records into a MYSQL database using Perl DBI.  There 
are fourteen fields, each one of which has its corresponding variable in 
my program.  I want to execute the "bind_param" method for each one of 
them.  If you're not familiar with DBI here's an example of what I might 
code:
   $sth->bind_param( 1, $message_id );
   $sth->bind_param( 2, $from_name );
   ...
   $sth->bind_param( 14, $body );

Ugly.  So I have a list of those variable names, thus
   my @variable_name_list = ( '$message_id', '$from_name', ...
and I have a loop with a counter, like this
   for ( my $i = 1; $i<=14; $i++ ) {
       eval{ $ins_sth->bind_param( $i, $variable_name_list[$i-1] ) };
   }

 ... but the database is filling up with fields containing the literal 
name of my variables:

   mysql> SELECT message_id FROM mailitem;
   +-------------+
   | message_id  |
   +-------------+
   | $message_id |
   +-------------+

I know that it's to do with when the variable name "becomes" the 
variable value, but I've tried multiple combinations of $, \$, and 
nested 'eval' and can't hit it.  Can someone help me work out how to do 
this?  Yes, I could have coded fourteen statements and had it working by 
now, but it's a matter of elegance!

-- 

Henry Law            Manchester, England


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

Date: Sun, 21 Feb 2010 15:08:30 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: Using eval to iterate over a set of Perl variables
Message-Id: <4b813e5e$0$22918$e4fe514c@news.xs4all.nl>

Henry Law wrote:

> I'm inserting new records into a MYSQL database using Perl DBI.  There 
> are fourteen fields, each one of which has its corresponding variable in 
> my program.  I want to execute the "bind_param" method for each one of 
> them.  [...]

This is in the DBI documentation:

Here’s a more fancy example that binds columns to the values inside a 
hash (thanks to H.Merijn Brand):

              $sth->execute;
              my %row;
              $sth->bind_columns( \( @row{ @{$sth->{NAME_lc} } } ));
              while ($sth->fetch) {
                  print "$row{region}: $row{sales}\n";
              }

Let it inspire you to do your bind_params properly.

-- 
Ruud


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

Date: Sun, 21 Feb 2010 14:13:16 +0000
From: Henry Law <news@lawshouse.org>
Subject: Re: Using eval to iterate over a set of Perl variables
Message-Id: <V_adnUyL8YDqohzWnZ2dnUVZ8oVi4p2d@giganews.com>

Dr.Ruud wrote:
> Henry Law wrote:
> 
>> I'm inserting new records into a MYSQL database using Perl DBI.  There 
>> are fourteen fields, each one of which has its corresponding variable 
>> in my program.  I want to execute the "bind_param" method for each one 
>> of them.  [...]
> 
> Let it inspire you to do your bind_params properly.

Inspired by the good doctor, to whom thanks, and also prompted by the 
intellectual exercise of presenting my problem, I've solved it:

   for ( my $i = 1; $i<=$field_count; $i++ ) {
       $ins_sth->bind_param( $i, eval($variable_name_list[$i-1]));
   }

The "bind_param" method simply wants a value.

-- 

Henry Law            Manchester, England


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

Date: Sun, 21 Feb 2010 16:04:38 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: Using eval to iterate over a set of Perl variables
Message-Id: <4b814b86$0$22942$e4fe514c@news.xs4all.nl>

Henry Law wrote:
> Dr.Ruud wrote:
>> Henry Law wrote:

>>> I'm inserting new records into a MYSQL database using Perl DBI.  
>>> There are fourteen fields, each one of which has its corresponding 
>>> variable in my program.  I want to execute the "bind_param" method 
>>> for each one of them.  [...]
>>
>> Let it inspire you to do your bind_params properly.
> 
> Inspired by the good doctor, to whom thanks, and also prompted by the 
> intellectual exercise of presenting my problem, I've solved it:
> 
>   for ( my $i = 1; $i<=$field_count; $i++ ) {
>       $ins_sth->bind_param( $i, eval($variable_name_list[$i-1]));
>   }
> 
> The "bind_param" method simply wants a value.

Don't even consider eval. Best use a hash.

I would use the actual column names as keys, or use an id2name hash if 
needed.

You won't need it anymore in a proper solution, but remember that you 
can write
   for ( my $i = 1; $i<=$field_count; $i++ )
as
   for my $i ( 1 .. $field_count )

-- 
Ruud


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

Date: Sun, 21 Feb 2010 09:21:17 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Using eval to iterate over a set of Perl variables
Message-Id: <slrnho2jkf.6h8.tadmc@tadbox.sbcglobal.net>

Henry Law <news@lawshouse.org> wrote:

> I'm inserting new records into a MYSQL database using Perl DBI.  There 
> are fourteen fields, each one of which has its corresponding variable in 
> my program.  I want to execute the "bind_param" method for each one of 
> them. 

>    my @variable_name_list = ( '$message_id', '$from_name', ...
> and I have a loop with a counter, like this
>    for ( my $i = 1; $i<=14; $i++ ) {
>        eval{ $ins_sth->bind_param( $i, $variable_name_list[$i-1] ) };
>    }


You have disguised symrefs as an eval.

Let's try and avoid that...


> ... but the database is filling up with fields containing the literal 
> name of my variables:
>
>    mysql> SELECT message_id FROM mailitem;
>    +-------------+
>    | message_id  |
>    +-------------+
>    | $message_id |
>    +-------------+
>
> I know that it's to do with when the variable name "becomes" the 
> variable value, but I've tried multiple combinations of $, \$, and 
> nested 'eval' and can't hit it.  Can someone help me work out how to do 
> this?


# untested
my $p_num=1;
foreach my $var ( $message_id, $from_name ) {
    $ins_sth->bind_param( $p_num++, $var);
}


Look Ma! No eval!

:-)


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"


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

Date: Sun, 21 Feb 2010 07:59:30 -0800
From: David Harmon <source@netcom.com>
Subject: Re: Using eval to iterate over a set of Perl variables
Message-Id: <c4-dnY8Vo782xRzWnZ2dnUVZ_rWdnZ2d@earthlink.com>

On Sun, 21 Feb 2010 13:27:50 +0000 in comp.lang.perl.misc, Henry Law
<news@lawshouse.org> wrote,
>Ugly.  So I have a list of those variable names, thus
>   my @variable_name_list = ( '$message_id', '$from_name', ...

 - Stop using eval for this.
 - Put real references in your array.
 - Read perldoc -q "How can I use a variable as a variable name"


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

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 V11 Issue 2828
***************************************


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