olafmar has asked for the wisdom of the Perl Monks concerning the following question:
and I get as output:#!/bin/perl use strict; add_iLO3_data(); exit; sub add_iLO3_data() { $_ = "Memory | 0x0 | discrete | 0x4080| na + | na | na | na | na | na "; chomp; my @fields = split(/\|/); my $name = $fields[0]; $name =~ s/\s*//; $name =~ s/\s*$//; my $value = $fields[1]; $value =~ s/\s*//; $value =~ s/\s*$//; my $status = $fields[3]; $status =~ s/\s*//; $status =~ s/\s*$//; print "$name--$value--$status--\n"; # add to database my $id = get_sensor_id($name); my @variables = ("sensor_id", "OperationalStatus", "CurrentReading +"); my @readings = ($id, $value, $status); # here I add to DB } sub get_sensor_id($) { my $sensor = $_; print "sensor input: $sensor\n"; return 0; }
Memory--0x0--0x4080-- sensor input: Memory | 0x0 | discrete | 0x4080| na + | na | na | na | na | na
The goal of the complete script is to parse an output and save some log data to a sqlite3 database, I cut out most of it.
I would expect to get in $sensor only "Memory", since I pass the variable $name by value (I tried by reference as well) and, as shown in the first sub, the variable $name seemed fine.
Where am I wrong?
Thank you very much!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Wrong content of variable passed to sub
by AnomalousMonk (Archbishop) on Aug 20, 2013 at 23:33 UTC | |
by olafmar (Novice) on Aug 21, 2013 at 20:28 UTC | |
|
Re: Wrong content of variable passed to sub
by state-o-dis-array (Hermit) on Aug 20, 2013 at 22:55 UTC | |
by olafmar (Novice) on Aug 21, 2013 at 20:24 UTC | |
by afoken (Chancellor) on Aug 24, 2013 at 07:53 UTC | |
|
Re: Wrong content of variable passed to sub
by jwkrahn (Abbot) on Aug 21, 2013 at 04:53 UTC | |
by olafmar (Novice) on Aug 21, 2013 at 20:29 UTC |