RE: regrex question

2002-02-18 Thread mark crowe (JIC)

Or try:
$key =~ s/(\w+)/\u$1/g
Note, no need for the \w\w+ character class (in fact that doesn't work
right) and remember the 'g' modifier, to do all words, not just the first. 

Cheers

Mark C

 -Original Message-
 From: fliptop [mailto:[EMAIL PROTECTED]]
 Sent: 16 February 2002 14:07
 To: David Gilden
 Cc: [EMAIL PROTECTED]
 Subject: Re: regrex question
 
 
 David Gilden wrote:
 
  
  $key =Departure date;
  
  $key =~ s/([\w\w+])/\u$1/;
  
  
  --- Desired result:
  
  Departure Date
  
  What is wrong the above regrex?
 
 
 it's probably easier to use the ucfirst() function:
 
 my $key =Departure date;
 my @result = map { ucfirst } split /\s+/, $key;
 print join  , @result, \n;
 
 this prints
 
 Departure Date
 
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Trying to use the = notation to print the values from this hash

2001-11-14 Thread mark crowe (JIC)

If this is pasted from your script, then you're defining %Unix (with a
capital U) and trying to access %unix (with a lowercase u). That won't help
;-)

Cheers

Mark C

 -Original Message-
 From: AMORE,JUAN (HP-Roseville,ex1) [mailto:[EMAIL PROTECTED]]
 Sent: 14 November 2001 03:58
 To: Beginners@Perl. Org (E-mail)
 Subject: Trying to use the = notation to print the values from this
 hash
 
 
 Hello Perl Gurus,
 I'm trying to print anyone of these values using the = notation.
 I believe I can use = but not so sure how to use it.
 Can someone give me an example,...I tried different ways but 
 have exhausted
 all means.
 Any hints:)
 
 Many Thanks!
 
 %Unix= (SHELL = /bin/csh, 
PAGER = more, 
DB = mysql);
 
 print Value: ,= $unix{SHELL}\n; 
 
 
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: simple code

2001-11-12 Thread mark crowe (JIC)

Hi Henry

Have you looked at using substr to take each octamer from the start for the
sequence? It's probably a lot more efficient than splitting it into an array
and taking the first 8 bases each time (althought I'm pretty sure that was
exactly the way I did my first DNA scripts too :-)

Also, if it's any use to you, here is my reverse complement subroutine,
which you could use as the basis of a palindrome checker which tests for any
palindrome, rather than just the restricted set you are using (of course,
those may be all the ones that you're interested in). 

sub complement {
  # Reverse complements the supplied string
  my $seq = shift; # Get the string
  $seq = reverse $seq; # Reverse it (scalar, therefore character reverse)

  # Complement each base (IUPAC codes, upper and lower case)
  $seq =~ tr/GATCgatcRYMKrymkSWswHBVDhbvdNn/CTAGctagYRMKyrmkWSwsDVBHdvbhNn/;

  return $seq;
}

Cheers

Mark C

 -Original Message-
 From: Henry Hung-Yung Wang [mailto:[EMAIL PROTECTED]]
 Sent: 09 November 2001 15:31
 To: [EMAIL PROTECTED]
 Subject: simple code
 
 
 
 Hi All,
 
 I have just written some codes, but they are not doing what I 
 wanted them
 to do. Here are the codes:
 
 @motif= ('ACGTACGT', '', 'CCGGCCGG', 'GGCCGGCC');
 
 print Please enter sequences to be examined:\n\n;
 $dna=STDIN; chomp $dna;
 
 @dna=split (//, $dna);
 foreach $bp (0..$#dna-8){
 $eightmer=join ('', @dna[$bp, $bp+1, $bp+2, $bp+3, $bp+4, 
 $bp+5, $bp+6,
 $bp+7]);
  if ($eightmer=~ $motif[0]){
 print This sequence, $eightmer, is palindromic\n\n;
 } else {
 print There is no other palindromic sequences\n\n;
 exit;
 }
 }
 
 I am trying to take the input and make them into sequences of 
 8 letters.
 Then I want to match the sequences with the 'motif' defined 
 in the codes.
 However, when I run the program, the only motif that was 
 recognized was
 ''. What am I doing wrong here? Thanks for the help.
 
 Henry
 
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: To use MySQL or Postgresql database with perl project

2001-11-09 Thread mark crowe (JIC)

Rupert

I don't have much experience with PostgreSQL (I use mostly MySQL), but the
differences between the two are much less than you seem to think. MySQL is
fine for millions of records, and you would search it through an SQL query
in exactly the same way as PostgreSQL (ie using the DBI module). Of course,
if you *really* want to, you could download the whole thing into a hash and
search it using Perl.

Also don't worry about it needing a 'simple database structure' - MySQL is a
fully functional relational database program.

Below is an edited version of the comparison between MySQL and PostgreSQL
from the MySQL 3.23 documentation. The general gist is that if you want
speed, use MySQL, if you want the specific advanced features, use
PostgreSQL. But either way, use DBI.pm

Cheers

Mark C



24.2 How MySQL Compares to PostgreSQL
 If you need speed, MySQL is probably your best choice. If you need some
of the extra features that PostgreSQL can offer, you should use PostgreSQL. 

PostgreSQL has some more advanced features like user-defined types,
triggers, rules, and some transaction support ... However, PostgreSQL lacks
many of the standard types and functions from ANSI SQL and ODBC...

Normally, PostgreSQL is a magnitude slower than MySQL...

The most important things that PostgreSQL supports that MySQL doesn't yet
support: 

Sub select 
Foreign keys 
Stored procedures 
An extendable type system. 
A way to extend the SQL to handle new key types (like R-trees) 
MySQL, on the other hand, supports many ANSI SQL constructs that PostgreSQL
doesn't support. Most of these can be found at the crash-me Web page. 

If you really need the rich type system PostgreSQL offers and you can afford
the speed penalty of having to do everything transaction safe, you should
take a look at PostgreSQL. 







 -Original Message-
 From: Rupert Heesom [mailto:[EMAIL PROTECTED]]
 Sent: 08 November 2001 08:23
 To: Perl List
 Subject: To use MySQL or Postgresql database with perl project
 
 
 I am trying to put together a simple database app which 
 extracts details
 from an email mbox file and update the database with these details (2
 field records) only if they're unique.
 
 I've looked briefly at MySQL or Postgresql.  I am not familiar with
 either of them.  At first, I thought I'd be able to use MySQL 
 because of
 the simple database structure that I will use.  
 
 However, I foresee needing to search 100s of thousands or millions of
 records to make sure that my data to update the database with 
 is unique.
 
 Therefore the perl's method of dealing with databases, using 
 a hash will
 not be sufficient, due to my having to come up with a good 
 search method
 to search the hash rather than relying on a good SQL query for a
 Postgresql database.
 
 Am I correct in assuming that an SQL query (using Postgres) 
 will be more
 efficient than searching through a linked hash variable 
 (using MySQL)??
 
 
 -- 
 regs
 rupert
 
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Parsing lines from txt files.

2001-11-01 Thread mark crowe (JIC)

Hi Rami

You've got it right about $1 and $2, and also about capturing matches to
variables. Your problem is that if your regex fails on one part of the match
then none of the variables will be set. So in your example most of your
matches don't give a PID number because the regex has failed to match
completely. I've made a couple of changes and it now seems to work for me.

/\s*(\d+)\s+ # OK
([0-9][0-9])?:? # was ([0-9]?[0-9]?): if you don't have the two digits, 
# you won't have the trailing colon either, so that has
# to be optional too.
# To make it even shorter you could use (\d{2})?:?
# \d is shorthand for [0-9] and {2} means two of.
([0-9][0-9]):[0-9][0-9]\s+ # OK
(\\_)?\s*\-? # was (\\?_?)\s+\-? if you're going to have either both of
 # \ and _ or neither then '?' is best off outside the brackets.
 # You need to specify 0 or more spaces (\s*) rather that 1
 # or more (\s+) - I'm not sure why but it's probably something
 # to do with how the regex engine works.
(\w+)\s+ # OK
(\w)/; # not sure exactly what you're trying to do here, at the moment it's
   # failing on the sh -c lines, because \w doesn't match the '-'. On
   # the other lines it'sjust getting the first letter of the word after

   # the command. Maybe you want (?:-(\w))? - This will get an optional
 # single letter which follows a - sign. Look up non-capturing
   # parentheses for an explanation of (?:...)

If you have problems like this, it's easiest if you break down the regex
over several lines (using the x flag), then you can remove bits easily to
see where the failure is happening.

Cheers

Mark C

 -Original Message-
 From: Rami Al-Kabra [mailto:[EMAIL PROTECTED]]
 Sent: 31 October 2001 16:33
 To: [EMAIL PROTECTED]
 Subject: Parsing lines from txt files.
 
 
 Hello,
 
 I'm brand new to the world of Perl.  The topic I'm about to ask about
 might have been addressed before.  Sorry for the duplication, 
 if that's
 the case.
 
 My understanding is that whatever is between the parens in a 
 regexp get
 stored in a variable ($1,$2,...).  And, if you do a 
 
 ($var_name1,$var_name2) = regexp with parens around 
 interesting stuff to
 store,
 
 then the interesting stuff inside the parens get stored in 
 the vars you
 specify.  Am I understanding incorrectly?
 
 The last print statement in the code below outputs nothing after the
 pid =.  What am I doing wrong?
 
 Thanks,
 Rami
 ___
 $test_ps_txt_file = txt_file_name;
 
 print Opening test ps file  $test_ps_txt_file...\n;
 open (TEST_PS_FILE, $test_ps_txt_file) || die Couldn't open
 $test_ps_txt_file: $!;
 
 while (TEST_PS_FILE)
 {
   print Read line...\n;
   chomp; # used to removed newline char.
   print $_\n;
 
   #parse a line and store.
   print Parse line...\n;
   
 ($pid,$elapsed_hours,$elapsed_minutes,$char_combo,$command,$cmd_arg) =
 /\s*(\d+)\s+([0-9]?[0-9]?):([0-9][0-9]):[0-9][0-9]\s+(\\?_?)\s
 +\-?(\w+)\
 s+(\w)/;
 
   print pid = $pid\n;
 }
 ___
 
 Here are the contents of the txt file (just create a file and
 copy/paste):
 
  3847   00:26 -tcsh
   88403:29:36 perl test_meister.pl
  103401:36:33  \_ sh -c . setup_sh  cd /somedir  perl doit.pl
  103601:36:32  \_ perl doit.pl -w -a
  107601:36:31  \_ sh -c perl run.pl -w  some_log 21
  107701:36:31  \_ perl run.pl -w
  149701:34:48  \_ sh -c some_exe some_file_name 
 redirect_file_name 21
  149801:34:48  \_ some_exe dstest_control.out
 
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: module File::Copy

2001-07-31 Thread mark crowe (JIC)

Hi Franck

If copy is doing what I suspect, that could be your problem. I'm guessing
that the function is copy ('old_file', 'new_file'), rather than, as you've
used it copy('new_file', 'old_file'). If that is the case (check the
File::Copy documentation) then what your program would seem to do is open
your original file, make all the substitutions and save it (so far so good).
Then it copies the original file over top of the new file, and then deletes
this new copy. Oops.

Try swapping round the file names in the copy command, or comment out both
that and the unlink line.

Cheers

Mark

 -Original Message-
 From: COLLINEAU Franck FTRD/DMI/TAM
 [mailto:[EMAIL PROTECTED]]
 Sent: 31 July 2001 16:18
 To: Perl (E-mail)
 Subject: module File::Copy
 
 
 Hello!
 
 I have a problem with this code:
 
 #!/usr/bin/perl -w
 use File::Copy;
 open (CONCAT,lmi/concat.htm) || die impossible d'ouvrir concat.htm:
 $!\n;
 open (CONCAT2,lmi/concat2.htm) || die impossible d'ouvrir 
 concat2.htm:
 $!\n;
 while(CONCAT)
 {
   s/CENTER//i;
   print (CONCAT2 $_);
 }
  close (CONCAT);
  close (CONCAT2);
 copy(lmi/concat.htm,lmi/concat2.htm);
 unlink(lmi/concat2.htm);
 
 
 there are two problems: the instruction s/CENTER//i doesn't work and
 copying files doesn't work too.
 
 can anybody help me ?
 
 Thanks 
 
 Franck
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Destroying Database Handle

2001-07-30 Thread mark crowe (JIC)

Try $dbh - disconnect;

Cheers

Mark C

 -Original Message-
 From: Frank Newland [mailto:[EMAIL PROTECTED]]
 Sent: 30 July 2001 16:35
 To: [EMAIL PROTECTED]
 Subject: Destroying Database Handle
 
 
 Question about DBI
 
 I'm having success in preparing , executing and getting SQL 
 output when I
 use DBI.
 What I want to do is ensure that I close properly. 
 Q: What statement(s) do I need to prevent destroying database handle?
 
 Thanks,
 
 Frank
 ***
 #!/usr/bin/perl -w 
 use strict ;
 use DBI;
 my $dbh ; my $sth ; my $sql_stmt ; $data_row; 
 
 $dbh = DBI-connect(dbi:Oracle:oracle:qa_1,user, 
 password,{PrintError =0,
 AutoCommit =0 )) || die failed to login to Oracle \n;
 $sql_stmt =  EOF+ ;
 select comments from table_a where comments is not null
 EOF+ 
 
 $sth=$dbh-prepare($sql_stmt) || die Failure to prepare SQL 
 Statement \n ;
 $sth-execute || die Failure to execute SQL \n;
 $data_row=$sth-fetchrow_hashref;
 $comments = $data_row-{COMMENTS};
 
 print $comments ;
 **
 Output:
 185221202202110  ## desired output. .
 Database handle destroyed without explicit disconnect.
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: lost in hashes

2001-07-27 Thread mark crowe (JIC)

Looks like you want braces after d4 = (and the corresponding closing one)
rather than brackets - ie {  }, not (  ).

Cheers

Mark C

 -Original Message-
 From: Jerry Preston [mailto:[EMAIL PROTECTED]]
 Sent: 27 July 2001 15:12
 To: begginners
 Subject: lost in hashes
 
 
 Hi,
 
 I just can't see where I have missed it! 
 
 
 
   %T = {
  d4 = (
  names = [ , Ron,   Tony,  Jeff,  
 Scott,  ],
),
};
 
 
   print $query-popup_menu( -name='Test',
 -values  = $T{ d4 }{ names },
 -default = ''
   );
 
 Do you?
 
 
 Thanks for Your help!!
 
 Jerry
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Need help with errors - strict the problem?

2001-07-10 Thread mark crowe (JIC)

Craig

'my' doesn't initialise a variable, it just declares it. The variable still
needs a value assigned to it. If it was a problem with 'strict' you would
get an error along the lines of 'Global symbol $value requires explicit
package name at line n' at compile time (ie the program wouldn't even start
to run). The error you're getting instead means that you're trying to use
$value before it has been given a value. 

What it looks like is happening is that there is a problem with your while
loop

 while (defined ($line = $remote)) {
   $line = substr($line,1);
   if ($line =~ /^IP Address/){
   ($ipaddress, $value) = split(/\s+:/, $line);
   }
 }

If either $remote returns no lines or none of those lines starts with IP
Address, then no value will ever be put into $value and you will get the
errors you see (well done for using -w, otherwise you wouldn't have picked
these up :-). I don't know anything about IO::Socket, so I'm not sure that
you've got the usage right in 'while ($line = $remote)', but I suggest
that you put in a couple of print lines in that while loop to see why you're
not getting the data. Try:

 while (defined ($line = $remote)) {
print $line; # Add this here to see if the loop is working
$line = substr($line,1);
if ($line =~ /^IP Address/){
($ipaddress, $value) = split(/\s+:/, $line);
print $ipaddress; # This will test whether the if and split are
working.
}
 }

Cheers,

Mark C
 -Original Message-
 From: Craig Monroe [mailto:[EMAIL PROTECTED]]
 Sent: 06 July 2001 23:07
 To: [EMAIL PROTECTED]
 Subject: Need help with errors - strict the problem?
 
 
 I wrote the following program to find the WAN IP address of 
 router, then
 send it in an http request to the website of the organization for dns
 updating. Then, I have a mail message sent to myself 
 notifying me of the
 update.
 I received the following errors. I am still somewhat of a newbie, so
 please have a little patience with me. The error messages are as
 follows:
 
 
 Use of uninitialized value in print at
 c:\windows\desktop\perl_hacks\dns_lwp-mai
 l.pl line 87.
 
 Line 87 is print $value;
 I thought I initialized this with my value;
 Is this because of strict? How would I pass that value if that is the
 case?
 
 
 and the answer is..
 
 good 24.147.206.7
 
 Use of uninitialized value in concatenation (.) at
 c:\windows\desktop\perl_hacks
 \dns_lwp-mail.pl line 104.
 
 line 104 is %mail = ( To  = '[EMAIL PROTECTED]',
 



RE: defining a new line seperator

2001-07-04 Thread mark crowe (JIC)

You might also want to think about setting $/ =  rather than $/ = \n\n.
Using  will define the line separator as one *or more* blank lines, while
\n\n will match only a single one (so for example if there are three
consecutive \n's the third will be assigned to the next paragraph). See
perldoc perlvar for a better explanation.

Cheers

Mark C

 
 $/ is the var for this, so you should say:
  $/=\n\n;
 
 have a nice day.
 
 
 On Tue, 3 Jul 2001 [EMAIL PROTECTED] wrote:
 
  i'd like to define a new line separator as a simple blank 
 line. i have
  tried \n\n and even tried ^$ in the way of a regex, but to 
 no avail. is
  there a metacharacter specific to this?
 
  -cjm
 
 
 pozsy
 -- 
 
 



RE: Multiple files in a filehandle

2001-07-03 Thread mark crowe (JIC)

OK, I probably didn't phrase that very well. But can I open more than one
filename to a single filehandle, or alternatively use more than one
filehandle in a while loop?

What I want to do is something like this:
open FILEHANDLE file1 + file2;
while (FILEHANDLE) {do stuff}

I know I can use ARGV, but in the situation I'm trying to use it, it behaves
differently to a filehandle generated with 'open'. I'm trying to get batches
of a fixed number of records to process and want to load a fixed number of
records into an array (from two files, one after the other). Then if the
final array value contains something, I want to process that batch (since
I've got enough records), otherwise it means that I've run out of data
before having enough for a full batch, and want to save that data for later
analysis. 

Test code that duplicates the problem:
@ARGV = qw(test1 test2);
for $i(0..9) {$array[$i] = }
print @array;

Unless there are an exact multiple of 10 lines in file1 + file2, this
freezes up when it runs out of data (I guess because it's waiting for the
remaining data to finish the for loop). However with a filehandle from
'open', it does what I want (except of course I can only use one file) and
completes the for loop, putting (I think) undef in the remaining places. 

I've found a couple of workarounds, but really would like to use something
like the multiple file handling behaviour of ARGV with a conventionally
'open'ed filehandle - can it be done please?

Thanks 

Mark C

 -Original Message-
 From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]]
 Sent: 02 July 2001 16:53
 To: mark crowe (JIC)
 Cc: [EMAIL PROTECTED]
 Subject: Re: Multiple files in a filehandle
 
 
 On Jul 2, mark crowe (JIC) said:
 
 Please can anyone tell me if there is a way to open multiple 
 files to a
 single filehandle, or somehow carry out something 
 equivalent. I can do it by
 putting the filenames into @ARGV and then doing a while () 
 {loop}, but I'd
 like to use a specific filehandle name.
 
 There *IS* a specific filehandle being used -- ARGV.



RE: referencing a flat file DB

2001-06-28 Thread mark crowe (JIC)

Hi Jon

Hey, is this a competition to identify lapdancers or something? If so, don't
forget to post the URL up here when you've got it working ;-) (especially
since we now know all the answers)

Anyway, one thing that might be causing problems is these two lines in your
one_time sub
   $compare = { split (/:/, $stats)};
   @records = \$compare;

I think you'd be better off to use:
@records = split (/:/, $stats)

At the moment you are splitting to a scalar (which I think just puts the
first (or is it the last?) value from that split into the scalar) and then
assigning a reference to that scalar as an array. I'm sure that's not good
for you (and I'm a bit surprised that -w didn't pick it up, or haven't you
tried it from the command line?)

Other than that I can't see anything that should actually stop it working.
It's not the prettiest code I've ever seen though...

Cheers

Mark C


 Hello everyone,
   I am trying to create a simple cgi script that if a 
 user enters the
 correct information on a contest form, they are entered into 
 a flat-file DB.
 This I have conquered.  My next feat is that before I write 
 their personal
 information into the DB, I am comparing 3 fields from the DB 
 to 3 fields
 being submitted by the user for duplicate submissions in sub 
 one_time (the
 fields are phone number fields).  The problem is, is that I 
 never get a
 match and the user is able to submit an infinite amount of 
 time.  Here is my
 source code.  It's only about 65 lines.  Thank you for  your help!
 



RE: Re[2]: ? embed scalars in the sql

2001-06-26 Thread mark crowe (JIC)

Not entirely true. Try:
$string = 0.0;
print $string;
- prints 0.0

Now try it without the quotes around 0.0
- prints 0

So there is a difference between strings and numbers. In the $counter case
it doesn't make any difference, but for the above case it could be important
- 0.0 is true in a boolean evaluation, while 0 is false, for example. I
will admit I have no idea how often it is important though.

Incidentally, autoincrement also works for strings anyway, try:
$a = a; $a++; print $a;
so your example would work whether $a is being treated as a string or a
number 

Cheers

Mark C

 
 Hello mark,
 
 Tuesday, June 26, 2001, mark crowe (JIC) 
 [EMAIL PROTECTED] wrote:
 
 mcJ If I might make one other little comment - I suggest you 
 initialise $counter
 mcJ by $counter=0, rather than $counter=0; The former 
 makes it a number, the
 mcJ latter a string.
 (jfyi only)
 you are mistaken. all variables in perl saves as strings; then,
 perl converts string - depends of your needs.
 
 try:
 
 $a=0;
 $a++;
 print $a;
 
 Best wishes,
  Maximmailto:[EMAIL PROTECTED]
 
 



RE: Subject Prefix

2001-06-19 Thread mark crowe (JIC)

Not necessarily true, at least in my case. For example, Eduard's initial
mail came through as 
From: Eduard Grinvald To: beginners 
while Brett's reply was 
From: Brett W. McCoy To: Eduard Grinvald cc: beginners

Cheers

Mark C

On Tue, 19 Jun 2001, Eduard Grinvald wrote:

 Hello, this probably goes to the list admins ;)
 Is it possible to insert some sort of subject heading, like
[beginners-perl]
 or something to make the email screening easier?

You can get the same effect by sorting on the From: field.

Err, I mean To: field. :-)

-- Brett



Reading to a hash

2001-06-19 Thread mark crowe (JIC)

I wonder if anyone can help me with a question based more on curosity than a
desperate need to know. Say I have a data file with one key/value pair on
each line, which I want to read into a hash. I've been doing it in one of
two ways:

  while () {
($key, $value) = split;
$hash{$key} = $value;
  }

or 

  push @array, split while ;
  %hash = @array;

What I'm wondering is if there is anything like:
  push %hash, split while ; # which doesn't work, or
  %hash = split while ; # but that overwrites all but the last pair.

Thanks

Mark C
-- 

Dr Mark Crowe   John Innes Centre
Norwich Research Park
Tel/Fax: +44 (1603) 450012  Colney  
mailto:[EMAIL PROTECTED]   Norwich
NR4 7UH




RE: random graphix generator

2001-06-14 Thread mark crowe (JIC)

OK, so you know about srand, after that the Perl command is pretty easy.

$A = int (rand (NUMBER))

This generates a random integer between 0 and NUMBER, including 0 but not
including number - e.g int (rand (5)) will give 0, 1, 2, 3 or 4.

'rand' generates a random number up to the value defined by NUMBER, and
'int' takes the integer value (drops everything right of the decimal point,
as you put it). 

Cheers

Mark C

P.S. The parentheses are optional


Perhaps someone can give me a siple line
in basic the rnd (random) Command goes something like this
$A=fix(rnd*10)
(the fix drops everything right of the decimal point. results in nnumber
0 to 9)
what is it in perl? I've looked at perldoc.org, no luck
and at the perldocs -f rnd... no luck
what i'm trying to do is select a random graphic.gif for my website
backround.
I know about srand;
I'm new to perl, so be gentle and complete ;-)

LH




RE: Calling a Perl script with parameters

2001-06-13 Thread mark crowe (JIC)

Hi Edd

I wish to write a perl script that i can call from the command line 
and pass parameters to it in the call when running under unix, i.e

perl perlscript parameter1 parameter2

A few things you might like to try:

1) Start your script with #!/usr/bin/perl (or wherever perl lives on your
system). Then you won't need the 'perl' to begin the command line.

2) Put perlscript in a directory in your unix path. Then the command
'perlscript parameter1 parameter2' will run from anywhere.

3) $ARGV[0] = parameter1, $ARGV[1] = parameter2, etc.

Cheers

Mark C



RE: non-greedy *

2001-06-13 Thread mark crowe (JIC)

Hi Josh

I guess it's talking about *? - this will match the minimum number of times
for a sucessful match, rather than the maximum. 

Cheers

Mark C


Hi all,
   I'm reading Mastering Regular Expressions and it discusses a
non-greedy version of star. can someone explain how to write this
non-greedy version of star. (i.e. how does it differ than just *)

-- 

  - josh



RE: A Term::ReadKey question -- keep cursor put!

2001-06-13 Thread mark crowe (JIC)

Hi Matt

The \r option works fine, but an alternative is to use 'print \b' - this
will print a backspace character, and means you can have other stuff on the
line too. Try:
$|=1; for ($i=0; $i10; $i++) {print $i\b;sleep 1}
This method only works for single digit numbers though, since it only
backspaces a single character (although you could set up a routine to
backspace more depending on the length of the output number). 

$| = 1 turns on OUTPUT_AUTOFLUSH so it prints each time through the loop,
rather than one big rush at the end. The sleep is just there so you have
time to see the number before the next loop.

Cheers

Mark C

Hi Matt,

I'm very new to perl (a week or so), so this may not be the best way to do
this, but

for ($i=0; $i10; $i++) {printf %d\r,$i;}

This will (should?) print the number followed by a Carriage Return (no
linefeed), so the cursor returns to the start of the line.

Hope this is what you wanted

Mark


I'm trying something like:

for ($i=0; $i10; $i++){print $i;}

and have the numbers iterate in ONE PLACE at the cursor (i.e. print, 
then backspace,print the new number, etc). I'm having problems figuring
this out. Any ideas? 

Thanks

Matt



RE: Unexplainable behavior

2001-06-13 Thread mark crowe (JIC)

Try:
 if(exists($hash{s}) and $hash{s} ne T __and__ $hash{s} ne F) {

(underscore for emphasis, not code). Using the 'or' means that if $hash{s}
is T, ($hash{s} ne F) is actually true, so it continues with that block.

Cheers

Mark C

-Original Message-
From: Charles Lu [mailto:[EMAIL PROTECTED]]
Sent: 13 June 2001 15:53
To: [EMAIL PROTECTED]
Subject: Unexplainable behavior


The following snippet of code doesn't behave the way I want it to.  Yet i 
cannot see why?


$hash{s} = T;


if(exists($hash{s}) and $hash{s} ne T or $hash{s} ne F) {
print inside\n;
}
else{  print outside\n; }



the OUTPUT of this program prints   inside.  But I want it to go INSIDE 
only if the key s exists in the hash, AND the value of $hash{s} DOES NOT 
equal T OR F.Can anyone suggest what I might be doing wrong here?  
By the way, even if I comment out the line that contain
$hash{s} = T;,  the output still goes to INSIDE.


_
Get your FREE download of MSN Explorer at http://explorer.msn.com