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!
In reply to Wrong content of variable passed to sub by olafmar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |