in reply to extracting integers from bracketes when reading from file...
Seems to work for me ... what are you getting, and what are you expecting, for the sample log file you're showing?
gives me:#!/usr/bin/perl -w use strict; use warnings; while (my $file_content = <DATA>) { if ( $file_content =~ m/Vc3/ ) { my @numbers = $file_content =~ /\[(\d+)\]/g; { local $,=':'; print @numbers; print $/ } } } __DATA__ Item no.0: NameDepth [2] <0> Class: [1] NetElementObjectClass Instance +: (int) [2] <1> Class: [ 57 ] Vc3TtpSnkObjectClass Instan +ce: (int) [3] Item no.1: NameDepth [2] <0> Class: [1] NetElementObjectClass Instance +: (int) [2] <1> Class: [ 57 ] Vc3TtpSnkObjectClass Instan +ce: (int) [14]
$ perl ./x.pl 3 14Seems right to me - are you expecting to get the 57 as well? If so, you need to tell the regexp to ignore spaces:
Hope that helps.my @numbers = $file_content =~ /\[\s*(\d+)\s*\]/g;
|
|---|