in reply to problems parsing data

my $tftp = <<'__EOI__'; DeviceInformation: Contact: NOC 111-222-3333 Hostname: bob Location: Creek Manufacturer: Cisco Model: WS-C3750G-48TS-S (C3750 series) OSVer: 12.2(46)SE Processor: WS-C3750G-48TS (PowerPC405) ROMVer: 12.2(25r)SEE4 SerialNumber: Z4CF,FOC688 ServiceTypes: Power SystemImage: flash:c3750-advipservicesk9-mz.122-46.SE.bin SystemMemory: 134209536 __EOI__ my ($image) = $tftp =~ /^SystemImage:\s*([^\n]+)/m or die("No SystemImage\n"); print("$image\n"); # flash:c3750-advipservicesk9-mz.122-46.SE.bin

Replies are listed 'Best First'.
Re^2: problems parsing data
by zonevbkr (Initiate) on Jul 09, 2010 at 01:22 UTC

    Thanks for the quick reply. I'll try this out. Do have a question though, maybe there's no way to do it, but is there a way I can just pass the data from

    $res->result()

    Since the data will change from device to device, just trying to find a way to make it as simple as possible. Thanks again, Chris

      ah silly me, I just clued in that $res->result() returns a list of lines. Ignore my earlier posts.
      my ($image) = map { /^SystemImage:\s*([^\n]+)/ ? $1 : () } $res->resul +t();

        Well, at the risk of showing what little I know, I've added your suggestion and how have:

        use lib qw(blib lib); #use strict; use warnings; use Getopt::Long; use Pod::Usage; use Data::Dumper; use Opsware::NAS::Client; my($user,$pass,$host) = ('a', 'b', 'localhost'); my $help = 0; my $ip = '10.226.1.52'; #my $ip = '$tc_device_ip$'; my $nas = Opsware::NAS::Client->new(); my $res = $nas->login(-user => $user, -pass => $pass, -host => $host, +-nosession => '0'); $res = $nas->show_deviceinfo(ip => $ip); unless ($res->ok()) { printf STDERR ("*** error: %s\n", $res->error_message()); exit(1); } my ($image) = map { /^SystemImage:\s*([^\n]+)/ ? $1 : () } $res->resul +t(); print("$image\n"); # flash:c3750-advipservicesk9-mz.122-46.SE.bin $nas->logout();

        but am getting an error of: Use of uninitialized value in string at move_image.pl line 34 So, why can't I print $image, seems like a simple thing to do.

      Yes, the left hand side of =~ can be any expression, not just a variable.