perl program question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl program question
# 1  
Old 07-04-2007
perl program question

why does below program not work?

<> is producing nothing.. still waiting for input.. but i thought this would work?


Code:
#!/usr/bin/perl -w

use strict;
my @array2;

my @array1 = ("David Veterinarian 56", "Jackie Ass 34", "Karen Veterinarian 28");
$_ = @array1;

while (<>) {
        push(@array2,$&) if m/^\w+(?=\s+Vet)/;
}

# 2  
Old 07-04-2007
fixed it

Code:
#!/usr/bin/perl -w

use strict;
my @array2;

my @array1 = ("David Veterinarian 56", "Jackie Ass 34", "Karen Veterinarian 28");
print '@array1 is ' , "@array1\n";

my $i = 0;

while ($i <= $#array1) {
        $_ = $array1[$i];
        push(@array2,$&) if m/^\w+(?=\s+Vet)/;
        $i++;
}

# 3  
Old 07-04-2007
Try:
Code:
#!/usr/bin/perl -w

use strict;
my @array2;

my @array1 = ("David Veterinarian 56", "Jackie Ass 34", "Karen Veterinarian 28");

for (@array1)  {
        push(@array2,$&) if m/^\w+(?=\s+Vet)/;
}

# 4  
Old 07-04-2007
thanks!.. I guess that is better..
# 5  
Old 07-05-2007
no one remembers grep

Code:
#!/usr/bin/perl -w

use strict;
my @array2;

my @array1 = (  "David Veterinarian 56",
                "Jackie Ass 34",
                "Karen Veterinarian 28");


@array2 = grep { m/^(\w+)(?=\s+Vet)/ } @array1;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl program get a response before the program quits

I created a program, so a kid can practice there math on it. It dispenses varies math problems and the kid must input an answer. I also want it to grade the work they have done, but I can't find the best place for it to print out the grade. I have: if ( $response =~ m/^/ ) { $user_wants_to_quit... (1 Reply)
Discussion started by: germany1517
1 Replies

2. Shell Programming and Scripting

Question regarding whence program

Hi all, In production code, if using the whence command it picks the production file.if I am using the test code file. by using whence command it not picking the file. do you have any idea on this. Whence prodcode it picks the exact path of the prodcode. whence testcode. it... (1 Reply)
Discussion started by: ramkumar15
1 Replies

3. Shell Programming and Scripting

Perl program

can anyone help me out to write a code by connecting to the sql database and I need to print the list of tables present in the databse. any ideas please. (1 Reply)
Discussion started by: ramkumar15
1 Replies

4. Programming

Question regarding Bash program

Hello All, I am trying to write a small bash script to make my life easier for an analysis. I have multiple folders and inside them are 10 output files with an extension .pdbqt What I am trying to do is to read the folder content and then make a PyMol (.pml) file to load the molecules and then... (11 Replies)
Discussion started by: biochemist
11 Replies

5. Shell Programming and Scripting

Help regarding a Perl Program

I want to traverse a durectory for a particular file. Situataion is like this. Path is ABC/a/c/g. it has around 100 folders in it. Search a directory which has word "*latest*" in its path. and then from the latest go through z/x/c to file final.html. In total, i want it to go through... (4 Replies)
Discussion started by: hemasid
4 Replies

6. Programming

Perl program

Hi I am new to perl, i need to write a program to convert horizontal words to vertical eg: cat, dog, cow,.....(text file) this should be written as 1.cat 2.dog like this. can u pls help me to work out.. (4 Replies)
Discussion started by: nitha
4 Replies

7. Homework & Coursework Questions

Calling compiled C program with Perl program

Long story short: I'm working inside of a Unix SSH under a bash shell. I have to code a C program that generates a random number. Then I have to call the compiled C program with a Perl program to run the C program 20 times and put all the generated random #s into a text file, then print that text... (1 Reply)
Discussion started by: jdkirby
1 Replies

8. Shell Programming and Scripting

perl program

could i get any help with how to link this program together. i dont know what to put where the X's are print `flush`; thank(); #print thank header use Getopt::Std; # use declaration with the options function getopts("ld:") or usage() and exit; ... (3 Replies)
Discussion started by: livewire06
3 Replies

9. Shell Programming and Scripting

perl program

I wish to write a Perl program that will provide a listing of files in a directory. The files must be listed in sorted order by the file name. • By default, the program displays only file names. • By default, the program lists the files in the current directory. • The program must provide the... (2 Replies)
Discussion started by: livewire06
2 Replies

10. Programming

QUESTION...simple program?

I am new to the unix/linux environment. AND........ I need to create a mini shell..that displays prompt (i.e., READY:$), accepts a command from std-in, and prints the command and any parameters passed to it. HELP!!!! (8 Replies)
Discussion started by: jj1814
8 Replies
Login or Register to Ask a Question