Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search results for query: *

  1. cfmartin2000

    comparing two array's in perl

    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]...
  2. cfmartin2000

    Assistance editing a script to parse out some numbers...

    Try this. I didn't test it but it should grab the last set of digits given the string has the closing curly bracket. $record =~ /(\d+)\s*\}\s*$/m
  3. cfmartin2000

    Matching Keys in Two Files

    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!
  4. cfmartin2000

    Matching Keys in Two Files

    Try this to get "1VYW" into its own variable: my $variable_you_want = (split('\|', $_))[1]; print $variable_you_want . "\n";
  5. cfmartin2000

    Drop a table

    Thanks. I'm not an idiot but I feel like on in seeing how easy that is.
  6. cfmartin2000

    Drop a table

    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.
  7. cfmartin2000

    Preventing duplicate array values

    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 =~...
  8. cfmartin2000

    Preventing duplicate array values

    my %hash = (); unless (@AJmasterNAMES =~ /$AJsearch/g) { $hash{$AJsearch} = 1; print join("\n", keys %hash); } print "\n";
  9. cfmartin2000

    Trying to use WWW:Mech to login into a webpage

    What is the content after you submit?
  10. cfmartin2000

    Help with subroutine

    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...
  11. cfmartin2000

    Help with subroutine

    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).
  12. cfmartin2000

    Need help understanding something

    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... ###...
  13. cfmartin2000

    Is there a function to convert from binary to hexadecimal?

    This'll work: my %hex = ( 0000 => '0', 0001 => '1', 0010 => '2', 0011 => '3', 0100 => '4', 0101 => '5', 0110 => '6', 0111 => '7', 1000 => '8', 1001 => '9', 1010 => 'A', 1011 => 'B', 1100 => 'C', 1101 => 'D', 1110 => 'E', 1111 =>...
  14. cfmartin2000

    System Command Permissions

    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.
  15. cfmartin2000

    Replace first occurance in file

    For Tony's first example the '|' has to be escaped since '|' is regex speak for "or" It should read: $changed=$_=~s/\|No/\|Yes/
  16. cfmartin2000

    removing array elements

    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);
  17. cfmartin2000

    removing array elements

    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...
  18. cfmartin2000

    Break string into a list

    This works too: my @elements; my $string = 'Os6NaClPo9C'; (@elements) = $string=~/([A-Z][^A-Z]*)/g;
  19. cfmartin2000

    removing array elements

    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)...
  20. cfmartin2000

    Load arrays from a file

    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.

Part and Inventory Search

Back
Top