entering regular expressions from the keyboard

2007-08-20 Thread Christopher Spears
Hi! I'm trying to get back into Perl again by working through Intermediate Perl. Unfortunately, the Perl part of my brain has atrophied! I'm working on the second exercise of the second chapter. I'm supposed to write a program that asks the user to type a regular expression. The program then

syntax errors?

2006-03-28 Thread Christopher Spears
I'm trying to solve a problem in Intermediate Perl. Basically, I open a text file and read its information. Here is some text from the file: gilligan.crew.hut lovey.howell.hut 4721 thurston.howell.hut lovey.howell.hut 4046 professor.hut ginger.girl.hut 5768 gilligan.crew.hut laser3.copyroom.hut

dowloading files from O'Reilly

2006-03-27 Thread Christopher Spears
I'm working through the Intermediate Perl book. For Exercise 2 in Chapter 5 on page 49, I need to dowload a file called coconet.dat from the O'Reilly web site. I went through the site and could not find it. Does anyone have any idea where this file is? -- To unsubscribe, e-mail: [EMAIL PROTECT

loop until empty string

2006-03-23 Thread Christopher Spears
I've been reading the Intermediate Perl book and am trying to solve one of the exercises. I wrote a script that takes input from the keyboard and uses the input as a regular expression to search for files in a directory. If the script finds a match, the filename is printed out. #!/usr/bin/perl -

HUP vs signal 9

2005-10-24 Thread Christopher Spears
What is the difference between kill 1, SIGNAL and kill 9, SIGNAL ? By reading books and talking to people, I figured out that kill 1 is the HUP (hang up signal) and kill 9 is the kill signal. Don't they do the same thing (i.e. terminate a program)? I was told that kill 1 is a "nicer" way to

killing a program

2005-10-21 Thread Christopher Spears
I've been working on a script that will allow me to kill a certain program using the program's PID. #!/usr/bin/perl -w use strict; sub findPID { if (my $PID = `pgrep PROGRAM`) { return $PID; } else { return 0; } } my $fPID = &findPID(); if

perl equivalent of ps

2005-10-16 Thread Christopher Spears
Does Perl have the equivalent of ps in Unix? I've looked in my Programming Perl book, and I could only find getpgrp, which does the opposit of what I want to do. Here is a schematic of what I want to accomplish: 1) Search ps aux and locate process PROC. 2) Get PROC's PID. 3) Use the PID to kill

Hash of Arrays

2005-09-20 Thread Christopher Spears
I've been learning about data structures by reading the Programming Perl book. Here is a code snippet: while ($line = <>) { ($who, $rest) = split /:\s*/, $line, 2; @fields = split ' ', $rest; $HoA{$who} = [ @fields ]; } The part that confuses me is: ($who, $rest) = split /:\s*/, $li

@ARGV

2005-09-14 Thread Christopher Spears
>From what I understand, @ARGV contains invocation arguments. Then how come I cannot access the first element with $ARGV[0]? What would be the proper way to do this? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

strange result with reg exp

2005-09-14 Thread Christopher Spears
In the script I am writing, I use the following regular expression: $pass =~ tr/a-z/A-Z/s; If I give the expression a string like "Occ", then the expression will convert it to "OC" instead of "OCC"! What is going on? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail:

chdir

2005-09-14 Thread Christopher Spears
So what should I do? -Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

chdir

2005-09-14 Thread Christopher Spears
Here is a snippet of code I am working on: while (1) { print "cd $path: Y or N?\n"; chomp($answer = ); if ($answer =~ /^[nN]$/) { print "Enter a path: "; my $path = ; chomp($path); chdir $path or die "Can't cd to $path"; last; }elsif ($answer =~ /^[yY]

local variabless vs my

2005-09-13 Thread Christopher Spears
I've been reading the following docs on Perl subroutines: http://perldoc.perl.org/perlsub.html#Persistent-Private-Variables I just read the section on local variables and am completely confused. What is a local variable? How is local $x different from my $x? -- To unsubscribe, e-mail: [EMAIL

catching output from ping

2005-09-09 Thread Christopher Spears
I've decided to rework my Perl script that pings a blade and checks for nrnode: my @bladeNumbers = @ARGV; if (scalar @bladeNumbers == 0) { print "No blades entered!\n"; exit; } foreach $_(@bladeNumbers) { my $blade = "blade-".$_; print "$blade\n"; my $badPing = "Destination Hos

critique me script!

2005-09-08 Thread Christopher Spears
Can you critique my script, please? #!/usr/bin/perl -w use strict; #Automates pinging and checking a blade for the #nrnode. #Usage: checkDemon #Created by Chris Spears 9/7/05 version 1. while (1) { print "Enter a blade number: "; chomp(my $bladeNumber = ); my $blade = "blade-".$bladeNum

catchDate

2005-09-08 Thread Christopher Spears
I want to catch the various parts of the output of the date command. Here is my script: #!/usr/bin/perl -w use strict; my $date = system("date"); $date =~ /(\w+)/; my $day = $1; print "Day: $day\n"; Here is my output: Thu Sep 8 10:22:14 CEST 2005 Day: 0 What is going on? Does this mean t

deciphering regular expressions

2005-09-07 Thread Christopher Spears
I am trying to figure out what the following regular expression is look for: if ( $line =~ /(\/data\/Shows.*)"/ ) Is it trying to find a line that has the phrase dataShows in it? What is the double quote for? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL

dereferencing

2005-08-24 Thread Christopher Spears
I'm trying to brush up on my Perl by learning object oriented Perl! This may not be the best way to brush up on this subject, but I am sure that I will learn a lot! Here is a script: #!/usr/bin/perl -w use strict; my @array = [1, 2, ['a','b','c','d']]; my $arrayref = [EMAIL PROTECTED]; my $ar

What does this error message mean?

2005-06-12 Thread Christopher Spears
I am trying to update a script I wrote to automate g++. Here is an excerpt: #!/bin/perl -w use strict; my $number_of_args = @ARGV; open STDERR, ">./caught_errors" or die "Can't create caught_errors: $!"; if ($number_of_args == 0) { print "Not enough arguments!\n"; } foreach (my $i = 0;

equivalent of break command?

2005-06-12 Thread Christopher Spears
I'm trying to write a perl script that automates g++. There is an if statement in the script that basically works like this: if there are no arguments { print an error message break (end the program) } Is there an equivalent of break in perl? What should I be using instead? "I'm the las

critique my script!

2005-03-01 Thread Christopher Spears
I've been learning C++ using cygwin on my Windows PC and thought it would be handy to have a Perl script that automated features of g++. The script takes one to two invocation arguments: ./cedit somefile.C++ ./cedit somefile.C++ outputfile cedit runs g++. After the file is compiled,etc., any er

what does this error message mean?

2005-03-01 Thread Christopher Spears
amp;choose_vi; } elsif ($number_of_args == 2) { system "g++", $ARGV[0], "-o", $ARGV[1]; &read_ce; &choose_vi; } else { print "Too many arguments!\n"; print "Usage: ./cedit somefile.C++\n"; print "Usage (optional): ./c

printing lines from a file

2005-02-26 Thread Christopher Spears
Here is some code I am working on: #!/bin/perl -w use strict; my $number_of_args = @ARGV; open STDERR, ">./caught_errors" or die "Can't create caught_errors: $!"; if ($number_of_args == 0) { print "Not enough arguments!\n"; print "Usage: ./cedit somefile.C++\n"; print "Usage (optio

calling an invocation argument from @ARGV

2005-02-25 Thread Christopher Spears
I'm trying to automate g++ through a Perl script. Here is what I have written so far: #!/bin/perl -w use strict; my $counter; $counter = 0; for (my $i = 0; $i < @ARGV; $i++) { $counter++; } if ($counter == 0) { print "Not enough arguments!"; print "Usage: ./cedit somefile.C++";

shell scripting newsgroup

2005-02-21 Thread Christopher Spears
Is there a forum similar to this for shell scripting? I mainly work in csh. = "I'm the last person to pretend that I'm a radio. I'd rather go out and be a color television set." -David Bowie "Who dares wins" -British military motto "The freak is the norm." - "The Infernal Desire Machines

Similar C++ digest?

2005-02-01 Thread Christopher Spears
This digest has really helped me learn Perl, so I was wondering if there is a similar digest for beginning C++ programmers. -Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

remove a file ?

2005-01-30 Thread Christopher Spears
In regards to an earlier question about removing a file with Perl, couldn't you just use a system call or exec? system "rm filename"; or exec "rm filename"; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Is GOTO evil?

2005-01-05 Thread Christopher Spears
I heard a lot of people dislike goto. Why? When should I use this command? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

critique me script!

2004-12-20 Thread Christopher Spears
Here it is! Thanks for the help! Any critiques would be appreciated! #!/usr/bin/perl -w use strict; my $Pixarport = 7498; my $host = "lex"; my $Pixarfile = $Pixarport."@".$host; my $handles; my $features; my $count = 0; my $answer; print "Running check_licenses.\n"; my @input = `check_licenses

adding functionality

2004-12-15 Thread Christopher Spears
Here is the latest version of my script: #!/usr/bin/perl -w use strict; my $Pixarport = 7498; my $host = "lex"; my $Pixarfile = $Pixarport."@".$host; my @input; my $line; my $line_number; my $file_length; my @features_array; my @handles_array; my $handles; my $features; my $sizeof; my $counter =

moving to the next line

2004-12-15 Thread Christopher Spears
So everybody wants to know what I have been working on. I finally got permission to post this: #!/usr/bin/perl -w use strict; my $Pixarport = 7498; my $host = "lex"; my $Pixarfile = $Pixarport."@".$host; my @line; my $line; my @features_array; my @handles_array; my $handles; my $features; my $si

receiving input from different sources

2004-12-14 Thread Christopher Spears
I need to be able to receive input from the keyboard, but is being used to process a file and <> is not appropiate for this purpose. What can I do? I was told there was a way to do this with exec. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <

Re: asking for y or n

2004-12-14 Thread Christopher Spears
Thanks for the answer Chris! Now my question is how do I find out if it is actually on my machine! I don't want to have to download anything because I am writing this script on one machine and then I am going to send it to another to be used. perl -v yields: This is perl, v5.8.1-RC3 built for d

asking for y or n

2004-12-14 Thread Christopher Spears
I'm writing a Perl script where I ask the user a question similar to: Would you like to remove this file? Type y or n. How do I get Perl to receive the answer and act on it? I've been looking in some of my books and noticed two ways of receiving input and <>. What is the difference between th

regexp for a blank line

2004-12-13 Thread Christopher Spears
I have to write a script that processes text in a file. The text includes lots of blank lines. How can I tell Perl to skip the lines? I thought maybe something like: next if ($line =~ /\s+/); However, what if the line simply happens to have more than one whitespace. Even a sentence has whites

control loop question

2004-12-13 Thread Christopher Spears
Hi! Let's say I have a text file filled with: stuff stuff stuff Users sometext tom dick harry Users more sometext larry curly moe moe stuff stuff etc.