[22257] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4478 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 28 18:05:49 2003

Date: Tue, 28 Jan 2003 15:05:10 -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           Tue, 28 Jan 2003     Volume: 10 Number: 4478

Today's topics:
        ANNOUNCE: CGI::Widget::Tabs v. 1.06.01 <NO.koos.JUNK.pol.MAIL@raketnet.nl>
    Re: array slicing (Anno Siegel)
    Re: cgi-lib to cgi.pm conversion <tony_curtis32@yahoo.com>
    Re: cgi-lib to cgi.pm conversion <uri@stemsystems.com>
        cgi-lib to cgi.pm <bill@asgweb.net>
    Re: cgi-lib to cgi.pm <uri@stemsystems.com>
    Re: Entering backslashed values into variables when rea (Sara)
    Re: Entering backslashed values into variables when rea <flavell@mail.cern.ch>
        Newbie looking for direction (Kirk McElhearn)
    Re: Newbie looking for direction <nobody@dev.null>
    Re: Problem checking for newline in $_ input line (Sara)
    Re: Problem checking for newline in $_ input line (Tad McClellan)
    Re: question concerning using objects in a module (h\)
    Re: regex to escape special characters (Tad McClellan)
    Re: regex to escape special characters (h\)
    Re: regex to escape special characters <alex@alexbanks.com>
        regular expression question (James Lee)
    Re: regular expression question <jurgenex@hotmail.com>
    Re: regular expression question (Jay Tilton)
        regular expression (agape)
    Re: regular expression <gregs@trawna.com>
        Siebel COM objects with Perl -sample code (Daniel Jors)
    Re: Substituting words in Array with items from a hash? (h\)
    Re: Tainting individual variables <flavell@mail.cern.ch>
    Re: test for (non-)interactive program run (Anno Siegel)
    Re: Timestamps to thousandths of a second. <nobody@dev.null>
    Re: Timestamps to thousandths of a second. (Anno Siegel)
    Re: Timestamps to thousandths of a second. <nobody@dev.null>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 28 Jan 2003 21:45:53 +0100
From: Koos Pol <NO.koos.JUNK.pol.MAIL@raketnet.nl>
Subject: ANNOUNCE: CGI::Widget::Tabs v. 1.06.01
Message-Id: <b16q64$10ksqf$1@ID-171888.news.dfncis.de>

All,

This is the announcement for CGI::Widget::Tabs, version 1.06.01.
The changes for this version are:

1.06.01 (2003-01-26)
--------------------
This is a maintenance release.
    - Fixed: forgot the replace my private "require" with "use"
    - Some code rearrangements.

Enclosed is the README for reference.

Best regards,
Koos Pol



CGI::Widget::Tabs
=================



DESCRIPTION

CGI::Widget::Tabs lets you simulate tab widgets in HTML. You
could benefit from a tab widget if you want to serve only one
page. Depending on the tab selected you fetch and display the
underlying data. There are two main reasons for taking this
approach:

1. For the end user not to be directed to YAL or YAP (yet another
link / yet another page), but keep it all together: The single
point of entry paradigm.

2. As a consequence the end user deals with a more consistent and
integrated GUI. This will give a better "situational awareness"
within the application.

3. For the Perl hacker to handle multiple related data sources
within the same script environment.

As an example the following tabs could be used on a web page for
someone's spotting hobby:

      __________      __________      __________
     /  Planes  \    /  Trains  \    / Classics \
------------------------------------------------------
         _________
        /  Bikes  \
------------------------

As you can see, the headings wrap at three and a small
indentation is added to the start of the next row. The nice thing
about CGI::Widget::Tabs is that the tabs know their internal
state. So you can ask a tab for instance which heading has been
clicked by the user. This way you get instant feedback.



DOCUMENTATION

The documentation is included in the module. You can read it's
manpage after installation with `perldoc CGI::Widget::Tabs'. If
you prefer you can read the documentation before installation
with `perldoc ./Tabs.pm'



DEPENDENCIES

- CGI, CGI::Minimal or another CGI "object broker"
  with the param() method and with similar behaviour
- HTML::Entities
- URI
- A CSS style sheet for the tabs markup



INSTALLATION

To install this module type the following:

perl Makefile.PL
make
make test
make install



DOWNLOAD

You can download CGI::Widget::Tabs from CPAN at
http://cpan.perl.org. The latest version is always available from
the CGI::Widget::Tabs homepage at:
http://users.raketnet.nl/koos_pol/en/Tabs/index.html



COPYRIGHT AND LICENCE

Copyright (c) 2003 Koos Pol. All rights reserved.

This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.



CHANGES

These changes are against the previous version.  For a complete
history log, see the file 'CHANGES' in the distribution.

1.06.01 (2003-01-26)
--------------------
This is a maintenance release.
    - Fixed: forgot the replace my private "require" with "use"
    - Some code rearrangements.



-- 
KP
koos _ pol @ raketnet nl


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

Date: 28 Jan 2003 19:34:11 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: array slicing
Message-Id: <b16lvj$6dl$1@mamenchi.zrz.TU-Berlin.DE>

Abigail  <abigail@abigail.nl> wrote in comp.lang.perl.misc:
> Thens (thens@nospam.com) wrote on MMMCDXXXVII September MCMXCIII in
> <URL:news:20030128193145.38a3ac7c.thens@nospam.com>:
> []  Hi,  
> []      I want a simplistic solution to a problem that i have in slicing
> []  array.
> []  
> []  #! /usr/local/bin/perl -w
> []  
> []  use strict;
> []  
> []  # NUMBERS in order
> []  my @numbers = ( 'ONE', 'TWO', 'THREE', 'FOUR', 'FIVE' ) 
> []  
> []  # I want to print numbers greater than or equal to three
> []  # I expect a magical operation to return me the elements in the list after T
> []  
> []  print join(' ', <your code operating on @numbers>);
> 
> 
> print "@{[do {my $c; grep {$c || $_ eq 'THREE' && ++ $c} @numbers}]}\n";

  print "@{[grep { $_ eq 'THREE' .. !defined }  @numbers]}\n";

Anno


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

Date: Tue, 28 Jan 2003 13:42:54 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: cgi-lib to cgi.pm conversion
Message-Id: <873cndnjr5.fsf@limey.hpcc.uh.edu>

>> On Tue, 28 Jan 2003 18:27:30 GMT,
>> Uri Guttman <uri@stemsystems.com> said:

> OMG! i can't even begin to comment on how bad that code
> is. poorly formatted, perl4ish, no comments, redundant
> code all over the place, etc.

> i would scrap the whole thing and redo it from scratch.

And then "Bill Smith" posts an identical article.
Homework maybe?


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

Date: Tue, 28 Jan 2003 19:53:57 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: cgi-lib to cgi.pm conversion
Message-Id: <x71y2xf3u3.fsf@mail.sysarch.com>

>>>>> "TC" == Tony Curtis <tony_curtis32@yahoo.com> writes:

  >>> On Tue, 28 Jan 2003 18:27:30 GMT,
  >>> Uri Guttman <uri@stemsystems.com> said:

  >> OMG! i can't even begin to comment on how bad that code
  >> is. poorly formatted, perl4ish, no comments, redundant
  >> code all over the place, etc.

  >> i would scrap the whole thing and redo it from scratch.

  TC> And then "Bill Smith" posts an identical article.
  TC> Homework maybe?

hmm. but what a sick assignment. converting cgi-lib to cgi.pm is one
line of work. so i don't what this would teach at all. it is horrible
perl code regardless of the cgi nature of it.

uri

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


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

Date: Tue, 28 Jan 2003 12:38:51 -0700
From: Bill Smith <bill@asgweb.net>
Subject: cgi-lib to cgi.pm
Message-Id: <3E36DBBE.A2609204@asgweb.net>

Dear Sirs,
I am converting the search routine below, written for cgi-lib.pl to be
used with cgi.pm. It is not returning any found items as is..
Any help is appreciated and thanks in advance.


sub search
  {    

$test = "on";

$data_file_path = "$path/members/$session_username/data";


if (!-e $data_file_path){

if(param('new_member_activation')){
 &no_hits_message2;
}
else{
    &no_hits_message;
}
    exit;
}
else{
  foreach $criteria (@db_user_definable_field_order) {
      param($criteria =>~ s/~p~/\|/g); }

param('keywords' =>~ s/~p~/\|/g);

#if (param('boolean') eq "any terms") {
#   param('keywords' => ~ s/\s+/\|/g); }

#if (param('boolean') eq "as a phrase") {
#   param('as_a_phrase' => "on"); }

local($multi_input);
foreach $multi_input (@db_index_of_multi_inputs)
  {
   if (param($multi_input))
   {
@split_values= CGI::param($multi_input);
   param($multi_input => join("\|",@split_values));
   }
  }

  if (param('sort_by'))
    {
    $index_of_field_to_be_sorted_by = param('sort_by');
    }

if (param('max_hits'))
    {
    $max_rows_returned = param('max_hits');
    }

  if (param('days_ago'))
    {
($today_month,$today_day,$today_year) = split (/\//, &get_date);
$today = &jday($today_month,$today_day,$today_year);
$oldest_day = ($today - param('days_ago'));
($beginmonth, $beginday, $beginyear, $beginweekday) = &jdate($oldest_day);
param('date_begin' => "$beginmonth/$beginday/$beginyear");
    }

  if (param('previous_hits_button.x'))
    {
 param('new_hits_seen' => param('old_hits_seen'));
    }

  for ($i = 1;$i <= 20;$i++)
    {
  if (param($i.x))
    {
 $n = $i-1;
 param('new_hits_seen' => ($n * $max_rows_returned));
    }
   }

  ($total_row_count) = &submit_query(*database_rows);

foreach $number (@number_sort)
{ if ($index_of_field_to_be_sorted_by == $number)
{ $numeric_sort = "yes"; }
}

foreach $number (@date_sort)
{ if ($index_of_field_to_be_sorted_by == $number)
{ $date_sort = "yes"; }
}

  foreach $row (@database_rows)
    {
    @row = split (/\|/, $row);
    $sortable_field = $row[$index_of_field_to_be_sorted_by];

if ($numeric_sort eq "yes")
{

$sortable_field =~ s/\$//g;
$sortable_field =~ s/,//g;
$sortable_field =~ s/(\d+)([kK])/${1}000/gi;
$sortable_field =~ s/([^0-9\.]+)/ /g;
$sortable_field =~ s/^([^0-9\.]*)(\d+\.?\d*|\.\d+)(.*)$/$2/g;

unless ( $sortable_field =~ /^(\d+\.?\d*|\.\d+)$/ )
{ $sortable_field = 0; }

}

      if ($date_sort eq "yes")
{
($mo, $da, $yr) = split(/\//, $sortable_field);
 
        $mo = "0" . $mo
          if (length($mo) < 2);

        $da = "0" . $da
          if (length($da) < 2);

        $yr = ($century + $yr)
          if (length($yr) < 3);

        $sortable_field = $yr . $mo . $da;

}

    unshift (@row, $sortable_field);
    $new_row = join ("\|", @row);
    push (@new_rows, $new_row);
    }

  @database_rows = ();

 if ($numeric_sort eq "yes")
 {

#  sub numerically { $a <=> $b; }

  if (param('reverse'))
{
@sorted_rows = sort {$b <=> $a} @new_rows;
}
  else
{
@sorted_rows = sort {$a <=> $b} @new_rows;
}
  }

 else {
   if (param('reverse')) {
       @sorted_rows = sort { lc($b) cmp lc($a) } @new_rows;
   }
   else {
       @sorted_rows = sort { lc($a) cmp lc($b) } @new_rows;
   }
  }
              

  $i = 1;
  foreach $sorted_row (@sorted_rows)
    {
    @row = split (/\|/, $sorted_row);
    $sorted_field = shift (@row);
    push (@row, $i);
    $old_but_sorted_row = join ("\|", @row);
    push (@database_rows, $old_but_sorted_row);
    $i++;
    }




  if ($total_row_count < 1)
    {

    &no_hits_message;

    exit;

}

if (param('display_modification_form_button')) { $hits_seen = 0; }

else { $hits_seen = param('new_hits_seen'); }

    
  for ($i = 1;$i <= $hits_seen;$i++)
    {
    $seen_row = shift (@database_rows);
    }

  $length_of_database_rows = @database_rows;
                

  for ($i = $length_of_database_rows-1;$i >= $max_rows_returned;$i--)
    {
    $extra_row = pop (@database_rows);
    }

                
  $new_hits_seen = $hits_seen + $max_rows_returned;

  $old_hits_seen = $hits_seen - $max_rows_returned;

    &search_results_body;

      }#else  
}#Search end




sub submit_query
  {

  local(*database_rows) = @_;
  local(@fields);
  local($row_count);
  local($line); 
  local($exact_match) = param('exact_match');
  local($as_a_phrase) = param('as_a_phrase');
  local($case_sensitive) = param('case_sensitive');

  local($c_name, $c_fields, $c_op, $c_type);
  local(@criteria_fields);
  local($form_value);

  $row_count = 0;
 
  open(DATAFILE, "$data_file_path") ||
    &error("$data_file_path Read Database");
if($test){print qq~Database opened~; }
  while(($line = <DATAFILE>)) 
    {

      chop($line); 

      @fields = split(/\|/, $line);

    $not_found = 0;

    foreach $criteria (@db_query_criteria)
      {  
  ($c_name, $c_fields, $c_op, $c_type) = split(/\|/, $criteria);
  @criteria_fields = split(/,/,$c_fields);
  $form_value = param($c_name);
  if ($form_value)
{
      $not_found += &flatfile_apply_criteria(
    $exact_match,
    $as_a_phrase,
    $case_sensitive,
       *fields,
       $criteria,

$c_name,
$c_fields,
$c_op,
$c_type,
@criteria_fields,
$form_value);
if ($not_found != 0) { last; }
}
      }

    if ($not_found == 0)
      {if($test){print qq~Not found~; }
      push(@database_rows, join("\|", @fields));
      $row_count++;
      }

  } 

  close (DATAFILE);

  return($row_count);

  } # End of submit query

sub flatfile_apply_criteria
  {
if($test){print qq~Flat file~; }
  local($not_found);
  my($db_value);
  my($month, $year, $day);
  my($db_date, $form_date);
  my($db_index);
  my(@word_list);

  if (($c_type =~ /date/i) ||
      ($c_type =~ /number/i) ||
      ($c_op ne "="))
   {

    $not_found = "yes";

    foreach $db_index (@criteria_fields)
      {

      $db_value = $fields[$db_index];

      if ($c_type =~ /date/i) 
        {
($month, $day, $year) = split(/\//, $db_value);

        $month = "0" . $month
          if (length($month) < 2);

        $day = "0" . $day
          if (length($day) < 2);

        $year = ($century + $year)
          if (length($year) < 3);


        $db_date = $year . $month . $day;

        ($month, $day, $year) = split(/\//, $form_value);

        $month = "0" . $month
          if (length($month) < 2);

        $day = "0" . $day
          if (length($day) < 2);

        $year = ($century + $year)
          if (length($year) < 3);

        $form_date = $year . $month . $day;

        if ($c_op eq ">") 
  {
          return 0 if ($form_date > $db_date); 
          }

        if ($c_op eq "<") 
          {
          return 0 if ($form_date < $db_date); 
  }

        if ($c_op eq ">=") 
  {
          return 0 if ($form_date >= $db_date); 
  }

        if ($c_op eq "<=") 
  {
          return 0 if ($form_date <= $db_date); 
  }

        if ($c_op eq "!=") 
  {
          return 0 if ($form_date != $db_date); 
  }

        if ($c_op eq "=") 
  {
          return 0 if ($form_date == $db_date); 
  }

      } 

   elsif ($c_type =~ /number/i) 
     {
       
$form_value =~ s/\$//g;
$form_value =~ s/,//g;
$form_value =~ s/[a-zA-Z]//g;
$form_value =~ s/\s//g;

$db_value =~ s/\$//g;
$db_value =~ s/,//g;
$db_value =~ s/[a-zA-Z]//g;
$db_value =~ s/\s//g;
 
     if ($c_op eq ">") 
{
        return 0 if ($form_value > $db_value); 
}

      if ($c_op eq "<") 
{
        return 0 if ($form_value < $db_value); 
}

      if ($c_op eq ">=") 
{
        return 0 if ($form_value >= $db_value); 
}

      if ($c_op eq "<=") 
{
        return 0 if ($form_value <= $db_value); 
}

      if ($c_op eq "!=") 
{
        return 0 if ($form_value != $db_value); 
}

      if ($c_op eq "=") 
{
        return 0 if ($form_value == $db_value); 
}
      } # End of elsif ($c_type =~ /number/i)

    else 
      {

      if ($c_op eq ">") 
{
        return 0 if ($form_value gt $db_value); 
}

      if ($c_op eq "<") 
{
        return 0 if ($form_value lt $db_value); 
}

      if ($c_op eq ">=") 
{
        return 0 if ($form_value ge $db_value); 
}

      if ($c_op eq "<=") 
{
        return 0 if ($form_value le $db_value); 
}

      if ($c_op eq "!=") 
{
        return 0 if ($form_value ne $db_value); 
}
      } 
    } 
   } 

   else 
     { 

if ($as_a_phrase eq "on") { @word_list = $form_value; }

else { @word_list = split(/\s+/,$form_value); }

foreach $word (@word_list) { 
$word =~ s/\+/\plus/g; 
$word =~ s/[\+]+/\\\+/; 
$word =~ s/\*/\star/g;
$word =~ s/\?/\question/g; 
$word =~ s/\[/\lb/g;
$word =~ s/\(/parenthesis/g;
$word =~ s/\)/parenthesis/g;
$word =~ s/\$/dollarsign/g;
         } 

    foreach $db_index (@criteria_fields)
      {

      $db_value = $fields[$db_index];
      $db_value =~ s/\+/\plus/g;
      $db_value =~ s/\*/\star/g;
      $db_value =~ s/\?/\question/g;
      $db_value =~ s/\[/\lb/g;
      $db_value =~ s/\(/parenthesis/g;
      $db_value =~ s/\)/parenthesis/g;
      $db_value =~ s/\$/dollarsign/g;
      $not_found = "yes";

      my($match_word) = "";
      my($x) = "";

      if ($case_sensitive eq "on") 
{
        if ($exact_match eq "on") 
  {
          for ($x = @word_list; $x > 0; $x--) 
    {
            $match_word = $word_list[$x - 1]; 
            if ($db_value =~ /\b$match_word\b/) 
      {
              splice(@word_list,$x - 1, 1);
              } 
            } 
          } 
        else 
  {
          for ($x = @word_list; $x > 0; $x--) 
    {
            $match_word = $word_list[$x - 1];
            if ($db_value =~ /$match_word/) 
      {
              splice(@word_list,$x - 1, 1);
              } 
            } 
          } 
      } 
    else 
      {
      if ($exact_match eq "on") 
{
        for ($x = @word_list; $x > 0; $x--) 
  {
          $match_word = $word_list[$x - 1];
          if ($db_value =~ /\b$match_word\b/i) 
    {
            splice(@word_list,$x - 1, 1);
            }
          } 
        } 
      else 
{
        for ($x = @word_list; $x > 0; $x--) 
  {
  $match_word = $word_list[$x - 1];
          if ($db_value =~ /$match_word/i)
    {
            splice(@word_list,$x - 1, 1);
            }
          } 
        } 
      } 
    } 

    if (@word_list < 1) 
      {
      $not_found = "no";
      }
  } 

  if ($not_found eq "yes")
    {
    return 1;
    } 
  else 
    {
    return 0;
    }
  }


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

Date: Tue, 28 Jan 2003 19:45:31 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: cgi-lib to cgi.pm
Message-Id: <x78yx5f485.fsf@mail.sysarch.com>


why did you post this again?

uri

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


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

Date: 28 Jan 2003 13:53:54 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: Entering backslashed values into variables when read in from files
Message-Id: <776e0325.0301281353.19553876@posting.google.com>

Hal Vaughan <hal@thresholddigital.com> wrote in message news:<sukZ9.58338$VU6.45795@rwcrnsc52.ops.asp.att.net>...
> Tad McClellan wrote:
> 
> > Hal Vaughan <hal@thresholddigital.com> wrote:
> > 
> >> I'm not even sure what man or perldoc page to read for this.  I'd
  .
  .  
  .
> 
> You don't teach, do you?  As I said, I appreciate the help, but I certainly 
> wouldn't recommend you work in a position where people skills are required.
> 
> > 
>  <snip>
> > Stuff you input from a file is "data".
> > 
>

Hal:

Honestly I was a little put off here as well when I first discovered
CLPM, thinking I was being put down.  It took awhile to get to know
contributors, but I've discovered that if you listen carefully, calm
down, and re-read replies, sometimes several times, you realize there
is a lot of trusth in most of what they are saying. Even come back and
read it later if the tone annoys you. There were times I was lazy, or
a dumb-ass. I'm not saying YOU were either of these, but you can
imagine in a forum like this how many times the same things pop up?

Even now- scroll down, someone is looking for a regex for email
addresses. I can't tell you how many times that's been asked and
answered here. It seems obvious to me now to search for "regex email"
in google, but some people need to be reminded and scolded for wasting
bandwidth.  So it gets frustrating too from the guru side.

I was a hard lesson for me, but I hope in the end I've become a better
CLPM citizen and in some cases, I've hope actually contributed
something in return for all of the help people here have offered *.
Even though I'm not adept enough to always add something, I don't miss
an opportunity to thank those who assisted or tried to assist.

I've posted to motherboard groups, Python groups, c, linux, etc etc. I
haven't done a complete analysis of the entire usenet, but I can tell
you that the answers here are more complete, and from more
experienced, qualified people than any I've found anywhere else. Its a
shame that Larry and some other's have left because some of the
highest level conversation went with them, but even now thumbing
through various topics responded to by Tad and Anno and others, its
hard NOT to come away with some new approaches or novel ideas. Its a
Perl goldmine! I can't tell you how much better my Perl skills are as
a result of this CLPM community.

Anyhow that's been my experience here. I'd suggest you might consider
rephrasing your reply to what looked to me like a pretty durned
helpful, and actually pretty mild response. You shold seem some of the
scoldings I've had! Mostly deserved in retrospect :)


-Gx

* - generously I might add. If sometimes they want to show off or be a
little abusive for my ignorance or laziness, maybe that's a small
price to pay for them taking time from probably very busy schedules to
help me. And for no renumeration other than to assist a faltering
fellow perlista. Open Source HAPPENS here in CLPM, and is a concept
elsewhere..


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

Date: Tue, 28 Jan 2003 23:27:59 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Entering backslashed values into variables when read in from files
Message-Id: <Pine.LNX.4.53.0301282324340.16915@lxplus076.cern.ch>

On Jan 28, Hal Vaughan inscribed on the eternal scroll:

> Tad McClellan wrote:
>
> > In the first or second week of a first programming class, the
> > difference between what is code and what is data is taught.
[..]

> You don't teach, do you?

Somebody didn't do their homework - and it shows.

SCNR.


p.s: myself, I only rarely do any kind of profiling on other usenauts;
but if I'm going to stick my neck out and make _that_ kind of comment,
then I think I would have a quiet check-up on them first.


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

Date: Tue, 28 Jan 2003 21:43:36 +0100
From: kirk@mcelhearn.com (Kirk McElhearn)
Subject: Newbie looking for direction
Message-Id: <1fpin0c.1vxgt89t23i8N%kirk@mcelhearn.com>

I am currently writing a book about using the command line with Mac OS
X.

http://www.mcelhearn.com/unix.html

This has naturally led me to explore some things that I have never
looked at before. Since Mac OS X comes with several languages (such as
Perl, but also TCL, Python, etc.) I thought it would be useful to learn
a bit of one of these languages, both to talk about using such tools in
my book, but also to learn to program. The sheer ubiquity of Perl makes
it seem like the best choice.

I have very limited programming experience (HyperCard and AppleScript
only), but would like to try and learn some of the basics of programming
Perl.

Would anyone like to point me in the right direction: books, tutorials,
on-line info, etc.?

Many thanks in advance,

Kirk 


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

Date: Tue, 28 Jan 2003 21:02:52 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: Newbie looking for direction
Message-Id: <3E36EEF1.3090701@dev.null>



Kirk McElhearn wrote:

> I am currently writing a book about using the command line with Mac OS
> X.
> 
> http://www.mcelhearn.com/unix.html
> 
> This has naturally led me to explore some things that I have never
> looked at before. Since Mac OS X comes with several languages (such as
> Perl, but also TCL, Python, etc.) I thought it would be useful to learn
> a bit of one of these languages, both to talk about using such tools in
> my book, but also to learn to program. The sheer ubiquity of Perl makes
> it seem like the best choice.
> 
> I have very limited programming experience (HyperCard and AppleScript
> only), but would like to try and learn some of the basics of programming
> Perl.
> 
> Would anyone like to point me in the right direction: books, tutorials,
> on-line info, etc.?
> 
> Many thanks in advance,
> 
> Kirk 
> 

Perl comes with pretty comprehensive (notice I didn't say 
comprehensible:-) documentation, as well as a tool to read and search 
that documentation, called perldoc. To learn how to use perldoc, type

perldoc perldoc


Start by reading the FAQs. You can get an overview by typing

perldoc perlfaq

and you can read each of the nine perlfaq documents by typing something 
along the lines of

perldoc perlfaq4

(substitute the desired number instead of the 4).

To find out if there is a FAQ dealing with the topic "foo" you would type

perldoc -q foo

For example, perldoc -q book will give you info about Perl books, and 
you should avail yourself of this facility.

Good luck.



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

Date: 28 Jan 2003 13:27:47 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: Problem checking for newline in $_ input line
Message-Id: <776e0325.0301281327.5259e3be@posting.google.com>

"J. F. Cornwall" <JCornwall@cox.net> wrote in message news:<jaxZ9.32353$Vh.7331@news2.central.cox.net>...
> Hi, I am working out the last problem in my script to parse Fortran
> comments (header blocks) and put the information into HTML pages.  I am
> having problems checking for the newline in some of the llines of text
> being parsed though.
> 
> Fortran comment line:
> 
> "C *(\n)"
> 
> C in column 1, variable number of spaces, variable number of "*" chars.
> 
> If I get a line like this in the header block, I want to skip over it,
> so I try this:
> 
> #  check for blank line after "c *", else strip "c *" and print comment
> if (s/^C\s+\*+\n//i)
>     {  $ignore_fg = 1;  $purpose_fg = 0;  print "</I> <BR>\n";  }
> else
>     {  s/^C\s+\*+\s+/ /i;  print $_;   }
> }
> 
> The "^C\s+\*+" part is working as far as I can tell, but it isn't
> recognizing the newline "\n" part of the pattern matching.  Any
> suggestions?
> 
> Jim Cornwall
> jcornwall@cox.net

Hi Jim:

You probably want to look at the "s" and "m" switches for regexes.
Without them your regex will work only "up to" the first \n.

Cheers,
Gx


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

Date: Tue, 28 Jan 2003 16:31:49 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Problem checking for newline in $_ input line
Message-Id: <slrnb3e16l.7ub.tadmc@magna.augustmail.com>

Sara <genericax@hotmail.com> wrote:
> "J. F. Cornwall" <JCornwall@cox.net> wrote in message news:<jaxZ9.32353$Vh.7331@news2.central.cox.net>...

>> if (s/^C\s+\*+\n//i)

> You probably want to look at the "s" 


s///s will not change anything.

The "s" option changes the meaning of the dot metacharacter, it
has no effect (other than making the maintainer "hiccup" in
understanding it) when there is no dot in the pattern.


(I don't remember fortran ignoring case. Does it?)


> and "m" switches for regexes.


That one he _does_ need.

s///m changes the meaning of the ^ and $ anchors.


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


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

Date: Tue, 28 Jan 2003 20:29:47 +0100
From: "Michael Peuser \(h\)" <post@mpeuser.de>
Subject: Re: question concerning using objects in a module
Message-Id: <b16lld$5s3$07$1@news.t-online.com>


"Mark Wirdnam" <mark.wirdnam@stud.unibas.ch> schrieb im Newsbeitrag
news:3c6df95c.0301281050.68879695@posting.google.com...
> Hello!
>
> I have tried to understand as much of perltoot as I could (for the
> moment). As you will notice immediately I am an inexperienced amateur
> trying to program a rather large project. In an attempt to keep things
> clear for myself I am seperating the program's tasks into modules.

This is good - in fact a very unusual idea for a newbie ;-) I am sure you
will improve your skills step by step!
>
> Here is how I am writing code at the moment:

[...]

> I hope I have understood correctly that this has nothing to do with
> inheritance, right? I'm just using packages within a package.

Quit! There is not always a need for inheritance (and even less in Perl,
where you can easily  "implant" a new variable into a given class (though
this is not very "clean" in fact)).
The profesional term is you are making an "association" between those two
classes: a very common construct, with wide theoretical background in entity
relation modells (=relational data bases) and UML . Best forget about this
immediately and progress as you have started...
>
> But the way I'm doing it is a lot of typing and not very easy to read.
>
The main problem generally is the $this-> prefixing - but you can't help it.
I do not see this "lot of typing"... Use intermediate variables if you want
to improve on it a little bit. They do not cost much, because everything is
just a "pointer".

> So is there something wrong with this way? What would be a more
> maintainable way?
>
What you do is perfectly right!

> I read this newsgroup with great pleasure, finding helpful advice here
> everyday. I would be very grateful to get advice also for this
> specific question.

Not much advice from me, but perhaps some assurance!

Kindly Mike




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

Date: Tue, 28 Jan 2003 13:07:33 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: regex to escape special characters
Message-Id: <slrnb3dl7l.6hg.tadmc@magna.augustmail.com>

Alex Banks <alex@alexbanks.com> wrote:

> is there a regular expression to escape all non alphanumeric characters in a
> string?


See the description for \Q in the "Quote and Quote-like Operators"
section of:

   perldoc perlop

and also:

   perldoc -f quotemeta

Or, just do it all yourself (untested):

   s/(\W)/\\$1/g;


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


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

Date: Tue, 28 Jan 2003 20:14:18 +0100
From: "Michael Peuser \(h\)" <post@mpeuser.de>
Subject: Re: regex to escape special characters
Message-Id: <b16koc$dlh$05$1@news.t-online.com>


"Alex Banks" <alex@alexbanks.com> schrieb im Newsbeitrag
news:3e36ce3c$0$219$cc9e4d1f@news.dial.pipex.com...
> is there a regular expression to escape all non alphanumeric characters in
a
> string?
>
> at the moment, i'm using s/\W//g to delete them, and s/\"/\\\"/g for
> individual characters that i need to escape, but it all looks a bit pete
> tong.


I am not QUITE sure what your problem is, maybe

    s/(\W)/\\$1/g

(But mind \n !!!)
There are a lot of things you can wrtite in the substitution part of s///e
when using the "execute" option.

> (couldn't find a regex-dedicated group. is there one?)
>

There also are some books about Regex  even one especially on Perl (look at
Amazon e.g.)

Kindly Mike




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

Date: Tue, 28 Jan 2003 19:17:59 -0000
From: "Alex Banks" <alex@alexbanks.com>
Subject: Re: regex to escape special characters
Message-Id: <3e36d769$0$219$cc9e4d1f@news.dial.pipex.com>


> Or, just do it all yourself (untested):
>
>    s/(\W)/\\$1/g;
>

Genius - that works a treat. Thanks Tad. I had tried a similar pattern, but
omitted the brackets around the first \W.




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

Date: 28 Jan 2003 14:27:13 -0800
From: csejl@yahoo.com (James Lee)
Subject: regular expression question
Message-Id: <146277ca.0301281427.292ab582@posting.google.com>

Hi,

What would be the best way to split table7 into table and 7?  Also, is
there a way to increase that 7 to 8 (table7 -> table8) without
splitting it?  Thanks.

-James


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

Date: Tue, 28 Jan 2003 22:37:35 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: regular expression question
Message-Id: <PCDZ9.2474$jj1.1039@nwrddc02.gnilink.net>

James Lee wrote:
> What would be the best way to split table7 into table and 7?  Also, is
> there a way to increase that 7 to 8 (table7 -> table8) without
> splitting it?  Thanks.

A simple
    s/7/8/;
should work just fine.

jue




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

Date: Tue, 28 Jan 2003 22:47:41 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: regular expression question
Message-Id: <3e370684.212275223@news.erols.com>

csejl@yahoo.com (James Lee) wrote:

: What would be the best way to split table7 into table and 7?

That depends entirely on what feature you think marks the boundary
between 'table' and '7'.

Burst it after the fifth character?  One character before the end?
Between alphabetic characters and digits?

If it's that last choice,

    my $foo = 'table7';
    my( $alphas, $digits ) = $foo =~ /^(\w+)(\d+)$/;

: Also, is
: there a way to increase that 7 to 8 (table7 -> table8) without
: splitting it?

    $foo++;



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

Date: 28 Jan 2003 12:18:16 -0800
From: bionic_man1@yahoo.com (agape)
Subject: regular expression
Message-Id: <3e5aae09.0301281218.6461bf68@posting.google.com>

Hi:

I am trying to do the following:
given a text file with such fields in it:

-term1 /my/home/directory -term2 a.v -term3 15000 -last "var1 var2
var3 var4" -t4 /my/current/  -last_one "variable1 variable2" -term4
xyz


The above could be in any order but any switch(-term1 or -term2 or
-last and so forth) is followed by a value of some sort. I desire out
of this lengthy text to remove anything that is passed to " "  which
in this case is -last and the quotes after it as well as -last_one and
quotes after it. My resultant should look like this:

term1 /my/home/directory -term2 a.v -term3 15000 -t4 /my/current/
-term4 xyz

Any reg exp you provide is helpful.
Agape


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

Date: Tue, 28 Jan 2003 21:47:39 GMT
From: Greg Schmidt <gregs@trawna.com>
Subject: Re: regular expression
Message-Id: <ogud3vodtamf21dqlubjta7d1te9jeku3o@4ax.com>

On 28 Jan 2003 12:18:16 -0800, bionic_man1@yahoo.com (agape) wrote:

>Hi:
>
>I am trying to do the following:
>given a text file with such fields in it:
>
>-term1 /my/home/directory -term2 a.v -term3 15000 -last "var1 var2
>var3 var4" -t4 /my/current/  -last_one "variable1 variable2" -term4
>xyz
>
>
>The above could be in any order but any switch(-term1 or -term2 or
>-last and so forth) is followed by a value of some sort. I desire out
>of this lengthy text to remove anything that is passed to " "  which
>in this case is -last and the quotes after it as well as -last_one and
>quotes after it. My resultant should look like this:
>
>term1 /my/home/directory -term2 a.v -term3 15000 -t4 /my/current/
>-term4 xyz
>
>Any reg exp you provide is helpful.
>Agape

$str =~ s/ -\w+ ".*?"//g
works for me.  \w matches any word character, including letters, numbers
and underscores, which covers your sample and any other I can think of.
You need the ? after the .* to make it non-greedy, or else in your
example it will match everything from  "var1  through to  variable2"
and you'll lose the -t4 term.

There may well be more complex situations that you need to handle that
this won't cover.  If so, post them and someone more knowledgeable than
I will help fix it. :-)

-- 
Greg Schmidt (gregs@trawna.com)
  Trawna Publications (http://www.trawna.com/)
    Fiction Into Film List (http://fictionintofilm.trawna.com/)
      Seven Wonders of the Web (http://7ww.trawna.com/)


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

Date: 28 Jan 2003 14:56:23 -0800
From: drjors@hotmail.com (Daniel Jors)
Subject: Siebel COM objects with Perl -sample code
Message-Id: <4e47e1ab.0301281456.7bd7522c@posting.google.com>

I figure out somebody would look after this sample, after all....
 .. please let me know if you have a better way of doing it... 

use Win32;
use Win32::OLE;
use Win32::OLE::Variant;
use Win32::OLE::Const ('Siebel Data BusObject Interfaces');
$Win32::Ole::Warn=3;
$sbl=Win32::OLE->new ('SiebelDataServer.ApplicationObject') || die
"CreateObject: $!" ;
@acc=('Name','Location');

my $y=Variant(VT_I2|VT_BYREF,8);
my $boo=Variant(VT_BOOL,1);

$sbl->LoadObjects('c:\sieb002\bin\s5f.cfg',$y);die "unable to load
objects" if $y;
$sbl->Login('test','abc',$y);die "unable to login. Error $y" if $y;

$bo=$sbl->GetBusObject('Account',$y);die "unable to GetBusObj. Error
$y" if $y;
$bc=$bo->GetBusComp('Account - All',$y);die "unable to
GetBusComponent. Error $y" if $y;

$bc->ClearToQuery($y);hSblErr('unable to clear to query');
foreach $itm(@acc){$bc->ActivateField($itm,$y);hSblErr('error
activating name')};

$bc->SetSearchSpec('Location',qq('905274851243900'),$y);
hSblErr('error in first record');

$bc->ExecuteQuery(1,$y);hSblErr('error in executing Query');
$boo= $bc->FirstRecord($y);hSblErr('error in first record');
die 'unable to find' unless $bc->FirstRecord($y);
foreach $itm(@acc){push @row,$bc->GetFieldValue($itm,$y)};
print "@row";

    


sub hSblErr(){
    return unless $y; print "Error $y: ".$sbl->GetLastErrText()."
@_[0]";die}


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

Date: Tue, 28 Jan 2003 20:56:27 +0100
From: "Michael Peuser \(h\)" <post@mpeuser.de>
Subject: Re: Substituting words in Array with items from a hash?
Message-Id: <b16n7d$m8o$06$1@news.t-online.com>


"Mac" <4.spam@cox.net> schrieb im Newsbeitrag
news:37da63be.0301280940.db246fa@posting.google.com...
> I have read a file (a template for a webpage) into an array.
> I am now trying to scan this array and substitute words that mach the
> keys in the hash %in and replace the words with the values in the hash
> %in. The goal is to take a web form and using the values replace the
> field names with the field values in a template file.

Please try to focus the problem mor tightly before posting a lot of code....

[....]
>     foreach $key (@lines) {
>         $key =~ s/$key/$in{$key}/g;
>     }

This is not well thought out ;-)
I assume you have LINES in $lines , so call them $line! As you want to check
for ALL keys do it (in a loop)!

Thus:
foreach $line (@lines) {
    foreach $key (keys %in) {
        $line =~ s/$key/$in{$key}/g
   }
}

There are variations, e.g.

   while (my ($before,$after) = each %in) {
        $line =~ s/$before/$after/g
}

You probably want to improve the matching conditions by some delimiting
conditions, else you would match parts of words etc.


Kindly
Mike




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

Date: Tue, 28 Jan 2003 19:55:00 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Tainting individual variables
Message-Id: <Pine.LNX.4.53.0301281951560.16915@lxplus076.cern.ch>

On Jan 28, Brian McCauley inscribed on the eternal scroll:

> Agghhh!  Another "small language".

Back in student days, many moons ago, I knew a chap whose approach to
each new problem seemed to be:

1. understand problem
2. design language suitable for solving problem
3. develop compiler for new language
4. job done.

SCNR.  [f'up suggested ;-) ]



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

Date: 28 Jan 2003 20:24:56 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: test for (non-)interactive program run
Message-Id: <b16ouo$6dl$2@mamenchi.zrz.TU-Berlin.DE>

Michael Kirchner  <michael.kirchner@unibw-muenchen.de> wrote in comp.lang.perl.misc:
> Espen Myrland schrieb:
> > Michael Kirchner <michael.kirchner@unibw-muenchen.de> writes:
> > 
> > 
> >>Hi
> >>
> >>Does anyone know how to check whether my program has been started from 
> >>an interactive shell or non-interactively by the cron-daemon? In the 
> >>interactive mode I want to have warning messages printed on the screen 
> >>and in the non-interactive case I want to write them to a specific file.
> >>
> > 
> > 
> > 
> > isatty(). 
> which module belongs it to?

POSIX.  But you don't need it, "-t STDIN" will serve the same purpose,
that is, make a guess if your program is run interactively.

> > But I think it's better to redirect the output from 
> > cron to /dev/null. just append  >  /dev/null 2>&1  in crontab.
> 
> I do so... with the normal output. But I want to keep error and warning 
> messages to see where problems may occur...

I'd still prefer to make the behavior explicit in the call.  The
standard method is to have interactive output on STDOUT and errors
on STDERR.  Then only redirect STDOUT to /dev/null.  If anything
appears on STDERR, cron mails it to you.  That's even better than
having to watch a file.

If you must use a file, make it a parameter of your program (with or
without one of the GetOpt:: modules), and make the default behavior
the one you have now.  Then give it an output file in crontab.

Both ways are better than guessing if you run under cron.

Anno


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

Date: Tue, 28 Jan 2003 19:25:41 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: Timestamps to thousandths of a second.
Message-Id: <3E36D825.1010902@dev.null>



Jeremy Gooch wrote:

> I need to generate a current date/timestamp in the format
> yyyymmddhhmmssxxx where xxx are the thousandths of a second.  The code
> must be portable across Solaris and NT.
> 
> Up until now, we've always used Date::Calc Today_and_Now because we've
> only needed stamps down to a second.  The docs imply that Date::Calc
> cannot go to any lower level of accuracy.
> 
> Time::HiRes can give me milliseconds since the epoch, but then I'd
> have to format it to pull out the date etc.
> 
> I'm sure I'm missing an obvious solution.  Can anyone point it out?
> 
> Thanks.
> 


I think you are almost there: if you have milliseconds since the epoch 
in $ms then you can just do something like

if ($ms=~/(.*)(...)$/){
	$epoch_seconds=$1;
	$xxx=$2;
} else {die "Time seems to be unhinged."};

Now you can turn $epoch_seconds into the yyyymmddhhmmss part of your 
time stamp like you always do, end then just tack on $xxx to get the xxx 
part of the time stamp.

I hope this helps.





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

Date: 28 Jan 2003 20:47:08 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Timestamps to thousandths of a second.
Message-Id: <b16q8c$6dl$3@mamenchi.zrz.TU-Berlin.DE>

Andras Malatinszky  <nobody@dev.null> wrote in comp.lang.perl.misc:
> 
> 
> Jeremy Gooch wrote:
> 
> > I need to generate a current date/timestamp in the format
> > yyyymmddhhmmssxxx where xxx are the thousandths of a second.  The code
> > must be portable across Solaris and NT.
> > 
> > Up until now, we've always used Date::Calc Today_and_Now because we've
> > only needed stamps down to a second.  The docs imply that Date::Calc
> > cannot go to any lower level of accuracy.
> > 
> > Time::HiRes can give me milliseconds since the epoch, but then I'd
> > have to format it to pull out the date etc.
> > 
> > I'm sure I'm missing an obvious solution.  Can anyone point it out?
> > 
> > Thanks.
> > 
> 
> 
> I think you are almost there: if you have milliseconds since the epoch 
> in $ms then you can just do something like
> 
> if ($ms=~/(.*)(...)$/){
> 	$epoch_seconds=$1;
> 	$xxx=$2;
> } else {die "Time seems to be unhinged."};
> 
> Now you can turn $epoch_seconds into the yyyymmddhhmmss part of your 
> time stamp like you always do, end then just tack on $xxx to get the xxx 
> part of the time stamp.

I'd prefer

    my ( $epoch_seconds, $xxx) = ( int $ms/1000, $ms % 1000);

They're numbers, after all.  No need to bring in strings and pattern
matching.

Anno


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

Date: Tue, 28 Jan 2003 22:54:47 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: Timestamps to thousandths of a second.
Message-Id: <3E370927.3080709@dev.null>



Anno Siegel wrote:

> Andras Malatinszky  <nobody@dev.null> wrote in comp.lang.perl.misc:
> 
>>
>>Jeremy Gooch wrote:
>>
>>
>>>I need to generate a current date/timestamp in the format
>>>yyyymmddhhmmssxxx where xxx are the thousandths of a second. 

[...]


>>
>>I think you are almost there: if you have milliseconds since the epoch 
>>in $ms then you can just do something like
>>
>>if ($ms=~/(.*)(...)$/){
>>	$epoch_seconds=$1;
>>	$xxx=$2;
>>} else {die "Time seems to be unhinged."};
>>
>>Now you can turn $epoch_seconds into the yyyymmddhhmmss part of your 
>>time stamp like you always do, end then just tack on $xxx to get the xxx 
>>part of the time stamp.
>>
> 
> I'd prefer
> 
>     my ( $epoch_seconds, $xxx) = ( int $ms/1000, $ms % 1000);
> 
> They're numbers, after all. [...]


Exactly. That's why at 1043791033055 milliseconds after the epoch your 
$xxx will be a two-digit sequence (55) while mine will be the 
three-digit 055 the OP wanted.

More germanely, are you sure int $ms/1000 is always the same as $ms with 
the last three digits cut off, given the inherent errors of 
floating-point arithmetic? I don't know, I can't come up with an example 
where your method gives a result that's different from mine, but I'm not 
sure there isn't one.





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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 4478
***************************************


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