The 'array_load' function populates the array with each
element within quotes. The 'array_save' function above,
outputs each element serially on one line.
However, I did manage a solution that works:
use: save_array ARRAY $filename
Code:
function array_assign
{
eval "$1=( \"\${$2[@]}\" )"
}
function array_save
{
local -a ARRAY; array_assign ARRAY $1
local FILE; FILE=$2
for ELEMENT in "${ARRAY[@]}"; do
echo $ELEMENT
done > $FILE
}
But it's not as elegant as the other functions. As the
function is part of a library that forms the foundation
of re-useable code concept, ideally it would have
been independent and used no named variables.
i have a file,like
1 3
4 5
6 7
8 9
i want to save it into an array.
and then i want to get every element, because i want to use them to calculate. for example: i want to calculate 1 + 3.
but i cannot reach my goal.
open (FILE, "<", "number");
my @arr;
while (<FILE>){
chomp;... (1 Reply)
Hi all,
How to:
Run a bash script, display on the screen and save all information in a file including error information.
For example:
I have a bash script called test.sh
now I want to run the test.sh and display the output on the screen and save the output including error info to a file.
... (1 Reply)
I have set up a bash script to run a long list of things that I need to time. I would like to redirect the output of time to a file. I have set it up like,
echo "Runtimes for servlet 4, 100K structures" > test_times.txt
echo "" >> test_times.txt
echo "runs where N=10" >> test_times.txt
echo... (7 Replies)
Hi,
I'm trying to write a bash script that takes a file and passes each line from the file into an array with elements separated by column.
For example:
Sample file "file1.txt":
1 name1 a first
2 name2 b second
3 name3 c third
and have arrays such as:
line1 = ( "1" "name1" "a"... (3 Replies)
Hi there.
i have created a program that in the end it will give output like this
1 2 3 4 5
10 9 8 7 6
11 12 13 14 15
.............. 17
i wonder how to save the output into a single string and into a file.
i.e 1 10 11 12 9 2 3 8 13 14 7 4 5 6 15 17 (in this order,... (3 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
Hi there.
i have created a program that in the end it will give output like this
1 2 3 4 5
10 9 ... (1 Reply)
I'm working on a script to execute a number of items. One being, editing particular files to add certain lines. I'm attempting to utilize sed, but, having issues when running from a bash script. Assistance is greatly appreciated.
My example:
sed -i '14 i\
# add these lines
add these lines to... (5 Replies)
I am trying to select a file in bash and save it to a directory. The below does run but no selected file is saved. Thank you :).
bash
# select file
printf "please select a file to analyze with entered gene or genes \n"
select file in $(cd... (4 Replies)
#!/bin/bash
X=(2H 4S 10D QC JD 9H 8S)
How do I unset the 10D from this array and save it to a file?
Please use CODE tags as required by forum rules! (5 Replies)
Discussion started by: cogiz
5 Replies
LEARN ABOUT SUSE
template::stash::context
Template::Stash::Context(3) User Contributed Perl Documentation Template::Stash::Context(3)NAME
Template::Stash::Context - Experimetal stash allowing list/scalar context definition
SYNOPSIS
use Template;
use Template::Stash::Context;
my $stash = Template::Stash::Context->new(\%vars);
my $tt2 = Template->new({ STASH => $stash });
DESCRIPTION
This is an alternate stash object which includes a patch from Craig Barratt to implement various new virtual methods to allow dotted
template variable to denote if object methods and subroutines should be called in scalar or list context. It adds a little overhead to
each stash call and I'm a little wary of applying that to the core default stash without investigating the effects first. So for now, it's
implemented as a separate stash module which will allow us to test it out, benchmark it and switch it in or out as we require.
This is what Craig has to say about it:
Here's a better set of features for the core. Attached is a new version of Stash.pm (based on TT2.02) that:
* supports the special op "scalar" that forces scalar context on function calls, eg:
cgi.param("foo").scalar
calls cgi.param("foo") in scalar context (unlike my wimpy scalar op from last night). Array context is the default.
With non-function operands, scalar behaves like the perl version (eg: no-op for scalar, size for arrays, etc).
* supports the special op "ref" that behaves like the perl ref. If applied to a function the function is not called. Eg:
cgi.param("foo").ref
does *not* call cgi.param and evaluates to "CODE". Similarly, HASH.ref, ARRAY.ref return what you expect.
* adds a new scalar and list op called "array" that is a no-op for arrays and promotes scalars to one-element arrays.
* allows scalar ops to be applied to arrays and hashes in place, eg: ARRAY.repeat(3) repeats each element in place.
* allows list ops to be applied to scalars by promoting the scalars to one-element arrays (like an implicit "array"). So you can do things
like SCALAR.size, SCALAR.join and get a useful result.
This also means you can now use x.0 to safely get the first element whether x is an array or scalar.
The new Stash.pm passes the TT2.02 test suite. But I haven't tested the new features very much. One nagging implementation problem is
that the "scalar" and "ref" ops have higher precedence than user variable names.
AUTHOR
Andy Wardley <abw@wardley.org>
<http://wardley.org/>
VERSION
1.63, distributed as part of the Template Toolkit version 2.19, released on 27 April 2007.
COPYRIGHT
Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
SEE ALSO
Template::Stash
perl v5.12.1 2009-04-07 Template::Stash::Context(3)