[16291] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3703 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 18 03:10:27 2000

Date: Tue, 18 Jul 2000 00:10:17 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <963904217-v9-i3703@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 18 Jul 2000     Volume: 9 Number: 3703

Today's topics:
        Reading/modifying file - perl script help <John_member@newsguy.com>
        searching for a # within a range padme67@my-deja.com
    Re: String and Hash question...rather urgent <godzilla@stomp.stomp.tokyo>
    Re: String and Hash question...rather urgent (Craig Berry)
    Re: Unflattening a multi-dimensional array (Abigail)
        Using fcntl in perl <csyang@cisco.com>
    Re: Using fcntl in perl (Abigail)
    Re: warn not working after re-opening STDERR scottbeck@my-deja.com
    Re: Yet another string manipulation question - <anuragmenon@my-deja.com>
    Re: Yet another string manipulation question - (jason)
    Re: Yet another string manipulation question - <anuragmenon@my-deja.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 17 Jul 2000 22:13:23 -0700
From: John Casey <John_member@newsguy.com>
Subject: Reading/modifying file - perl script help
Message-Id: <8l0p1j$i1f@drn.newsguy.com>

Problem :

      I have a sql script which creates Tables and Indexes.   I have
another file(say config file) which contains the details of the tables in the
following format:
      
      Tablename    Initialextent   NextExtent   PctIncrease
     
       EMP_TAB        10 m           5 m           0
       SAL_TAB        100 m          10 m          10
       GRD_TAB         200 m         25 m          0
       .......


I need to write a perl script which will "sync" the  initial/next/pctincrease
values of all the tables in the sql script as per the values in the config file.
(that is because i run the sql script on
systems of different disk capacities)

For eg:  the script needs to scan the sql file for  "create table statements"
and then get to the corresponding "storage clause of the statement" before
checking, lookingup in the config file and changing(if needed) in the sql file.
    
         create table EMP_TAB {
            OID int not null,
            Name varchar(255) null,
            ....
         }
         storage (initial 5 m  next 1 m pctincrease 50) tablespace empdata;

          would be changed to
           
            create table EMP_TAB {
               //*all the stuff same as above *//
            }
            storage (initial 10 m next 5 m pctincrease 0) tablespace empdata ;


          Any hints on the perl script?  I have been trying to work it out
as follows ..

****
open(SQLFILE, "sqlfilename") || die "cannot open sqlfile \n";
open (CFGFILE, "configfilename") || die "cannot open config file \n";
while (<SQLFILE>)
{
  chomp;
  if (/create \s+ table/)
  {
      my $tab = $_ ;
      $line = <SQLFILE>   until ( ($line =~ /storage/) || ($line =~ /;/) );
      if ($line =~ /storage/)
      {
        $line =~ /storage \s+ initial (\d+) k next (\d+) k pctincrease (\d+))/;
        my $initial = $1;
        my $next = $2;
        my $pcti = $3;
        $tab =~ /create table (\w+) \(/ ;
        my $TABLE_NAME = $1 ;
        @table_data = `grep $TABLE_NAME tbdata` ;
        chomp(@table_data);
        ($tblname,$initial_new,$next_new,$pcti_new,$junk) = split(/\s+/,@table)

*****

    And here is where i am wondering how do i write the new values back into
the file.  That is how do i modify the values in the file on fly?
Also, is the above approach correct at all?  

Any help is appreciated
thanks
John



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

Date: Tue, 18 Jul 2000 06:41:38 GMT
From: padme67@my-deja.com
Subject: searching for a # within a range
Message-Id: <8l0u71$4bj$1@nnrp1.deja.com>

I am new to Perl, cgi and coding...
That said I am trying to do a search on a database that will determine
if any value in the database falls into a user defined range.
1)I have a drop-down menu that a user can choose a price range(i.e.
$150,000-200,000 etc.)
2)When submitted my program looks through the db to find any values
that fall into the range chosen.

I can pattern match with words or phrases but finding a # in a range
has me stumped.  If someone could just push me in the right direction I
would be eternally grateful!

Thanks,
padme67


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


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

Date: Mon, 17 Jul 2000 21:23:21 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: String and Hash question...rather urgent
Message-Id: <3973DBB9.1E69D42E@stomp.stomp.tokyo>

"Vinod K. Menon" wrote:
 
> this is probably extremely elementary - but I am kinda new to perl
> and am trying to get something done in a hurry and hopefully will
> get a speedy reply - anyway, this is  what I want to do.


Well darn, yet another newbie to Perl. Amazing influx
rate of newbies to Perl. I am estimating somewhere in
the range of one-hundred to two-hundred fresh newbies
to Perl per month. Must be the free T-shirts.


(snipped)
 
> For example if I have initialized the hash as
 
> %hash1 = qw(a "10101"
>             b "20202");
 
> and the input string is ab,
> the output should be "10101,20202"

 
(subsequent article)

> the value that I plan to retrieve has spaces in the 
> sense that the value of the Key a is a string which
> is "1.0 2.0 3.0".  If the extra quotes cannot be used,
> then will

> %hash1 = qw(a 1.0 2.0 3.0
>             b 2.0 3.0 4.0);
> work or do I have to use individual assignment statements
> like $hash1("a") = "1.0 2.0 3.0";
> and so on for all keys?



> I appreciate all help..

Perhaps. My help is to suggest you make up your
mind what you want to do, stick with it, then
ask your question. You say you are in a hurry,
so formulate a question and, don't change your
parameters with each given answer. This would
save you precious time and annoy fewer people.


Godzilla!

-- 
$godzilla = "godzilla rocks!";
srand(time() ^ ($$ + ($$ << 15))); 
sub randcase
 { rand(40) < 20 ? "\u$1" : "\l$1" ; }
$godzilla =~  s/([a-z])/randcase($1)/gie;
print $godzilla; exit;


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

Date: Tue, 18 Jul 2000 06:22:48 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: String and Hash question...rather urgent
Message-Id: <sn7ttos1o53128@corp.supernews.com>

Vinod K. Menon (anuragmenon@my-deja.com) wrote:
: this is  what I want to do.
: 
: 1. Read in a string (String1)
: 2. Initialize a hash(Hash1) with a set of values
: 3. for every character in String1 in order from the first to the last,
:    extract the corresponding value from Hash1 using that character as
:    they key
: 4. concatenate the values extracted, in order,with a comma seperateing
: the values, to form a new string.
: 
: For example if I have initialized the hash as
: 
: %hash1 = qw(a "10101"
:             b "20202");
: 
: and the input string is ab,
: the output should be "10101,20202"

Changing your mapping slightly for convenience, and adding some error
handling to deal with undefined chars:

#!/usr/bin/perl -w
# hashtrans - hash-based character translation, for clpm
# Craig Berry (20000717)

use strict;

my %trans;

@trans{'a'..'z'} = (1001..1026);

while (<>) {
  chomp;
  print join(',', map { $trans{$_} || '*' } split //), "\n";
}


(By the way, that || would be repalced with ?? if LR triumphs. :)

-- 
   |   Craig Berry - http://www.cinenet.net/users/cberry/home.html
 --*--  "Beauty and strength, leaping laughter and delicious
   |   languor, force and fire, are of us." - Liber AL II:20


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

Date: 18 Jul 2000 01:21:59 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: Unflattening a multi-dimensional array
Message-Id: <slrn8n7rcs.v90.abigail@alexandra.delanet.com>

Matthew Stoker (matt.stoker@motorola.com) wrote on MMDXIII September
MCMXCIII in <URL:news:3973B2B4.F68CB68A@motorola.com>:
$$ I appologize if I overlooked this in a FAQ somewhere, but I have the
$$ following problem.
$$ 
$$ I have an array (@data_set) that is read from a file. I need to parse
$$ this large flat array into a multidimensional array (a list of lists in
$$ perlspeak). Anyway, what makes it tricky is that I don't know beforehand
$$ how many dimensions the multidimensional array should have or the number
$$ of elements in each dimension.  These are also read from the file into a
$$ second array @dim. Therefore:
$$ 
$$ @dim      = the desired number of dimensions 
$$ $dim[0]   = the number of elements in the 1st dimension
$$ $dim[1]   = the number of elements in the 2nd dimension
$$ .
$$ .
$$ .
$$ $dim[$#dim]= the number of elements in the last dimension
$$ 
$$ If I knew the number of dimensions beforehand, it would be easy to use a
$$ series of nested "for" loops as follows:
$$ 
$$ But since I don't know how many dimensions, I don't know how many nested
$$ loops to put in the code.  Any suggestions?


my    @dim  =               split " " => <INP>;
my    @data = do {local $/; split " " => <INP>};

my    $code = $multi = shift @data;';
map  {$code =~ s/\$multi/\$multi [\$x$_]/;
      $code = "for my \$x$_ (0 .. $dim[$_] - 1) {$code}";}
       reverse 0 .. $#dim;
eval  $code;


Golf, anyone?


Abigail
-- 
print v74.117.115.116.32, v97.110.111.116.104.101.114.32,
      v80.101.114.108.32, v72.97.99.107.101.114.10;


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

Date: Mon, 17 Jul 2000 21:48:51 -0700
From: Chien Yang <csyang@cisco.com>
Subject: Using fcntl in perl
Message-Id: <3973E1B3.CD741CC7@cisco.com>

Hello,

I am new to this newsgroup.  I would like to know how use the function
"fcntl()" to lock a file for writing.   Also, please tell me what do I
pass into the third parameter of "fcntl()"?


Thanks.


Chien



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

Date: 18 Jul 2000 01:37:02 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: Using fcntl in perl
Message-Id: <slrn8n7s96.v90.abigail@alexandra.delanet.com>

Chien Yang (csyang@cisco.com) wrote on MMDXIII September MCMXCIII in
<URL:news:3973E1B3.CD741CC7@cisco.com>:
() Hello,
() 
() I am new to this newsgroup.  I would like to know how use the function
() "fcntl()" to lock a file for writing.   Also, please tell me what do I
() pass into the third parameter of "fcntl()"?


That question cannot be answered. 'fcntl' gives you access to your
systems 'fcntl'. So, see your systems manpage about 'fcntl'.

If you want to lock files the Perl way instead of your systems way,
use flock.



Abigail
-- 
perl -Mstrict -we '$_ = "goto X.print chop;\n=rekcaH lreP rehtona tsuJ";X1:eval'


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

Date: Tue, 18 Jul 2000 06:44:09 GMT
From: scottbeck@my-deja.com
Subject: Re: warn not working after re-opening STDERR
Message-Id: <8l0ubn$4c9$1@nnrp1.deja.com>

In article <MPG.13de62c553bf1db89896e1@news>,
  elephant@squirrelgroup.com (jason) wrote:
> scottbeck@my-deja.com wrote ..
> >#!/usr/bin/perl -w
> >open STDSAVE, ">&STDOUT";
> >open ERRSAVE, ">&STDERR";
> >close STDOUT;
> >close STDERR;
> >print "This should not show up!\n";
> >
> >open STDOUT, ">&STDSAVE";
> >open STDERR, ">&ERRSAVE";
> >print "This is stdout and you should see this!\n";
> >warn  "This is a warn and you should see it!\n";
> >print STDERR "I am printing to STDERR!\n";
> >
> >
> >The warn line does not produce output to STDERR
> >but the print to STDERR does. Is this a bug or
> >a dumb mistake?
>
> works for me as expected with Perl 5.005_03 on WinNT .. all three
lines
> produce output to the console
>
> --
>   jason -- elephant@squirrelgroup.com --
>

Sorry, but I forgot to mention this does work on windows but not unixish
systems. I did try it on Win2k and WinNT and it does work.
The warn does not happen on the linux systems I tried it on.
RedHat 6.0, Mandrake 7.0, and Mandrake 7.1.

Thanks,
Scott


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


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

Date: Tue, 18 Jul 2000 05:01:17 GMT
From: Vinod K. Menon <anuragmenon@my-deja.com>
Subject: Re: Yet another string manipulation question -
Message-Id: <8l0oan$fu$1@nnrp1.deja.com>

In article <MPG.13de6209e7a8d3e79896e0@news>,
  elephant@squirrelgroup.com (jason) wrote:
> Vinod K. Menon wrote ..
> >Ok..here it is... there is an input string $String1
> >


Thanks for that code...but would it be too rude to say I am not
understanding it? I understand the rules being stored in the hash (I
think I do)...but what is the scalar variable $key and what is the
initialization etc? I am totally lost...please help..

Vinod.

> >Let me give an example:
> >
> >One Rule says 'a' can be followed by 'b'or 'e'
> >Another Rule says 'c' can be followed only by 'd'
> >Yet another Rule is 'e' can be followed only by 'k' or 'l'
>
>   my %rules = ( a => 'be', c => 'd', e => 'kl' );
>   my $char = 'X';
>
>   for my $key (keys %rules)
>   {
>     $String1 =~ s/$key([^$rules{$key}])/$key$char$1/g;
>   }
>
> >is there an easy function whatever in perl that can be used to
achieve
> >this. I can do a series of "if"s to do this..but is that the best
way?
> >any suggestions?
>
> a reasonably simple regex will handle those sorts of rules ..
basically
> the above will work with any number of those types of rules
>
> what we're using here is a negative character class .. for the first
> rule - the above regex becomes
>
>   $String1 =~ s/a([^be])/aX$1/g;
>
> so the [^be] matches any character other than 'b' or 'e' .. and the
> substitution is made .. we put capturing parens so that we can use $1
in
> the substitution to put whatever character back in place
>
> the hash is just an easy way of storing those rules - and iterating
> through them
>
> --
>   jason -- elephant@squirrelgroup.com --
>


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


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

Date: Tue, 18 Jul 2000 05:24:45 GMT
From: elephant@squirrelgroup.com (jason)
Subject: Re: Yet another string manipulation question -
Message-Id: <MPG.13de877031b101999896e8@news>

Vinod K. Menon wrote ..
>In article <MPG.13de6209e7a8d3e79896e0@news>,
>  elephant@squirrelgroup.com (jason) wrote:
>>   my %rules = ( a => 'be', c => 'd', e => 'kl' );
>>   my $char = 'X';
>>
>>   for my $key (keys %rules)
>>   {
>>     $String1 =~ s/$key([^$rules{$key}])/$key$char$1/g;
>>   }
>
>Thanks for that code...but would it be too rude to say I am not
>understanding it? I understand the rules being stored in the hash (I
>think I do)...but what is the scalar variable $key and what is the
>initialization etc? I am totally lost...please help..

ok .. line by line with documentation references in parens

>>   my %rules = ( a => 'be', c => 'd', e => 'kl' );

create a new hash %rules with three keys 'a', 'c' and 'e' which have 
three values - respectively 'be', 'd' and 'kl' (perldata) .. using the 
=> operator for clear distinction between key/value pairs (perlop)

>>   my $char = 'X';

hopefully that line needs no explanation .. I only did it so that it's 
easy to change the separator character

>>   for my $key (keys %rules)

for every key in %rules set $key to the key and loop (perlsyn)

>>   {
>>     $String1 =~ s/$key([^$rules{$key}])/$key$char$1/g;

the =~ operator tells Perl to perform this substitution on the $String1 
scalar (perlop)

after the variable interpolation - the three substitutions will be

  s/a([^be])/aX$1/g
  s/c([^d])/cX$1/g
  s/e([^kl])/eX$1/g

the [^be] means any character OTHER THAN 'b' or 'e' and the parens do 
the $1 magic (perlre)

>>   }

now .. if that's still not clear then start reading some documentation 
 .. take any of the words in parens above and feed it through perldoc 
from the command line .. eg.

  perldoc perlop

then read the doco

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Tue, 18 Jul 2000 05:50:50 GMT
From: Vinod K. Menon <anuragmenon@my-deja.com>
Subject: Re: Yet another string manipulation question -
Message-Id: <8l0r7m$2f0$1@nnrp1.deja.com>

Ok..I did understand how it works and thanks a lot ..I really really
appreciate it!!

Vinod


>
> > >Let me give an example:
> > >
> > >One Rule says 'a' can be followed by 'b'or 'e'
> > >Another Rule says 'c' can be followed only by 'd'
> > >Yet another Rule is 'e' can be followed only by 'k' or 'l'
> >
> >   my %rules = ( a => 'be', c => 'd', e => 'kl' );
> >   my $char = 'X';
> >
> >   for my $key (keys %rules)
> >   {
> >     $String1 =~ s/$key([^$rules{$key}])/$key$char$1/g;
> >   }
> >
> > >is there an easy function whatever in perl that can be used to
> achieve
> > >this. I can do a series of "if"s to do this..but is that the best
> way?
> > >any suggestions?
> >
> > a reasonably simple regex will handle those sorts of rules ..
> basically
> > the above will work with any number of those types of rules
> >
> > what we're using here is a negative character class .. for the first
> > rule - the above regex becomes
> >
> >   $String1 =~ s/a([^be])/aX$1/g;
> >
> > so the [^be] matches any character other than 'b' or 'e' .. and the
> > substitution is made .. we put capturing parens so that we can use
$1
> in
> > the substitution to put whatever character back in place
> >
> > the hash is just an easy way of storing those rules - and iterating
> > through them
> >
> > --
> >   jason -- elephant@squirrelgroup.com --
> >
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>


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


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

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


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