473,385 Members | 1,587 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Storing a variable in a variable

I need to do the following.

I want a variable ($var1) to be stored in ($var2).

This is what I have done:

#!/usr/bin/perl

@var1 = `cat ~/data.txt`; #this file contains also IPs which I need.

foreach $line (@var1){
if($line =~ /[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}/){;
print $line;
}
}

This should print out all the IPs.

It doesn't work. When I do in terminal:
grep [[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\} data.txt

That works.

Any ideas?

P.S. My final aim is to do this:
$var1 = var2;
print $var2;
Jun 27 '07 #1
2 1291
prn
254 Expert 100+
Hi yahalom,

It's not clear to me what you want to store in which variable. (or why) Your line:
Expand|Select|Wrap|Line Numbers
  1. @var1 = `cat ~/data.txt`;
suggests that you want var1 to be an array (of ip addresses?), but your lines:
Expand|Select|Wrap|Line Numbers
  1. $var1 = var2;
  2. print $var2;
suggest something else. (Perhaps you want var1 to contain the name of the second variable?) And why is that your "final aim"? What relation does that have to the IP addresses(?) that you said you were after?

Does data.txt contain anything other than IP addresses? Do you want that other stuff filtered out? What do you really want to do with the IP addresses that are in data.txt?

Best Regards,
Paul
Jun 27 '07 #2
KevinADC
4,059 Expert 2GB
Already answered on the other forum where the question is posted. Problem is escaping the meta characters in the regexp is killing the meta meaning and treats them literally:

\{1,3\}
Jun 27 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Francisco | last post by:
I have this problem: I have a database with information about games, and users are able to vote for them. Everytime a user votes for a game I store the unique game name into a session variable (an...
3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
3
by: Sean | last post by:
HI, I have a shopping cart in which I am trying to use breadcrumb style navgiation. I need to be able to display the categroy heading relating to the section of the site a visitor is using i.e...
12
by: Alfonso Morra | last post by:
I have the ff code for testing the concept of storing objects: #include <vector> #include <iostream> using namespace std ; class MyClass { public: MyClass(){
0
by: Sandra | last post by:
I am using a VB6 COM object with an asp.net project. I am storing the COM object in a session variable but am having a problem accessing the COM object from the session variable. I am getting...
4
by: Frank Rizzo | last post by:
In classic ASP, it was considered a bad idea to store VB6-created objects in the Application variable for various threading issues. What's the current wisdom on storing objects in the Application...
2
by: Angel | last post by:
I am storing a value into a javascript variable that was keyed into a text control. When the code performs a postback, the value that was stored into a clientside variable no longer exists. Is...
2
by: newjazzharmony | last post by:
All, I'd appreciate it if someone could answer these questions for me. This scenario applies to an ASP dot net application that is deployed in a web farm. 1) Does the application live in a...
1
by: None | last post by:
Hi, I have developed webshop application using asp.net 1.1. I'm using DataGrid in one of the pages of my site. During the page load the DataGrid will be binded by around 7500 products(rows). At...
3
by: RSH | last post by:
Hi, I have a situation where I have created an object that contains fields,properties and functions. After creating the object I attempted to assign it to a session variable so i could retrieve...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.