in reply to Re: extracting value in a string after checking value after colon ':'
in thread extracting value in a string after checking value after colon ':'

Thanks

but this is not working, i get error like

Use of uninitialized value $_ in pattern match (m//) at gpu.pl line 8
  • Comment on Re^2: extracting value in a string after checking value after colon ':'
  • Download Code

Replies are listed 'Best First'.
Re^3: extracting value in a string after checking value after colon ':'
by hippo (Archbishop) on Jan 30, 2019 at 09:10 UTC

    You will not get that if you run the code as written, so you have changed something. Post the full code you are running as an SSCCE if you would like assistance to debug further.

Re^3: extracting value in a string after checking value after colon ':'
by Laurent_R (Canon) on Jan 30, 2019 at 09:36 UTC
    Please show the code that gave you this Use of uninitialized value $_ warnings. It would not happen with the code as written by Athanasius , so you must have done something differently.
Re^3: extracting value in a string after checking value after colon ':'
by t-rex (Scribe) on Jan 30, 2019 at 08:33 UTC

    secondly if you see the file, there are many lines, i only want to extract the node number (250,251..) only if string cpus: is empty after the colon.

    Hope i made my question clear

      i only want to extract the node number (250,251..) only if string cpus: is empty after the colon.
      That's seems to be exactly the output from Athanasius's code. Or, if it is not, then please explain in which respect Athanasius's code does not produce what you want. And also show the code you're using.

      How are you reading the lines from the file ?

      #!/usr/bin/perl use strict; use warnings; my $infile = 'infile.txt'; open my $fh,'<',$infile or die "Could not open $infile : $!"; my $lineno = 0; while (<$fh>){ ++$lineno; if (/^ node \s+ (\d+) \s+ \w+ : $ /x){ print "lineno $lineno : $1\n"; } } close $fh; print "$lineno lines read from $infile\n";
      poj