This works:
#! /usr/bin/perl
use strict;
use warnings;
my @array = ("john","larry","kevin","peter","mike");
my @exclude = ("john","kevin");
foreach my $i ( 0..$#exclude ) {
foreach my $x ( 0..$#array ) {
if ( $array[$x]
&& $exclude[$i]
&& $array[$x]...
travs69's will work. This, I think (because I have not tested it) is incorrect:
if ($_=/^pdb\/|/)
I believe you will need to escape the '|'
Try if ($_=/^pdb\|/) and notice the "\|" That's what travs69 does. Sorry if I lead you down the wrong path.
Thanks travs!
Is it possible to use an IF statement to drop a table if it exists and skip it otherwise?
I am trying to get this (pseudo-code):
IF(istable(table1)) then DROP table1 else do nothing
Thanks in advance.
My bad. I did not really notice line this before:
unless (@AJmasterNAMES =~ /$AJsearch/g) {
Your code should go as follows:
my %hash = ();
# $item will contain each item from the array in turn
foreach my $item (@AJmasterNAMES){
#skip items that do not match
next unless ($item =~...
This will produce an warning like the one you see:
my $a = undef;
print "$a is a nice variable\n";
Try it, you'll see.
So to correct this do the following or something like it:
print "$a is a nice variable\n" if $a;
...or...
if($a){
print "$a is a nice variable\n";
} else {
print...
Looks to me like it maybe a scoping issue. Where do you have $sth defined. Looks like the second sub uses the same $sth. That could be a problem. Either local the variable or have two statement handles defined ($sth_A, $sth_B).
To answer your question:
The word 'param' is the key and 'DlrGrp' is the value. Likewise, the word 'value' is the key and 'AMOS' is the value.
To see this more clearly, and if you have the time, you can use this:
use Data::Dumper; #At the beginning of your script.
#And then later...
###...
If you are running on Unix you will need to change the command to "cp"
Also, try:
system('copy', 'file1', file2');
Or you can...
use File::Copy;
copy('src_file', 'dest_file');
The last is the best option since it is generally a cross-platform implementation.
Yes exactly. Your @some_array contains the values from your %some_hash slice.
Like this:
my %hash;
@hash{'A'..'Z'} = (1..26); #Same as %hash = (A=>1, B=>2, C=>3 ....)
my @list;
@list = @hash{ qw/A B D F/ };
#@list = (1, 2, 4, 6);
It's a hash slice which I believe is a list context. This is similar to $hash{'an_item'} being in a scalar context. The clue here is the curly brackets which let you know you are working with a hash.
You could write the same thing as follows keeping everything in a scalar context:
foreach my...
Try something like this:
my %list_1;
my %list_2; #contains the elements to remove from list 1
open (FILE1, "file1") or die $!;
while(<FILE1>){
chomp($_);
$list_1{$_}=1;
}
close(FILE1);
open (FILE2, "file2") or die $!;
while(<FILE2>){
chomp($_);
$list_2{$_}=1;
}
close(FILE1)...
Each time you read from a file using <FILE>, you read 1 record from a file. By default, the record is delimited by a carriage return("\n"). However, this can be changed using the $/ Perl variable. Glad I could help.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.