473,321 Members | 1,748 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,321 software developers and data experts.

use external data import value into script

cassbiz
202 100+
I am working on a shopping cart and have implemented a coupon hack for it. What I am trying to do (without breaking it too bad, LOL ) is to have the values stored in an external file and call it when needed. Like require in PHP.

Is there an example of a line of code that will work for my application?

I have been reading all over the web and see require() and use() but am not understanding the foobar

currently the line I want to import into the script is

Expand|Select|Wrap|Line Numbers
  1. @sc_discount_logic = ("1005||||5%", "1500||||5.00");
  2.  
Thanks in advance
May 10 '07 #1
8 2639
KevinADC
4,059 Expert 2GB
You probably just want to use the open() function to open and read the file into a variable. In it's simplest form:

Expand|Select|Wrap|Line Numbers
  1. open(FH,"yourfile.txt") or die "$!";
  2. my @data = <FH>;
  3. close(FH);
May 10 '07 #2
cassbiz
202 100+
You probably just want to use the open() function to open and read the file into a variable. In it's simplest form:

Expand|Select|Wrap|Line Numbers
  1. open(FH,"yourfile.txt") or die "$!";
  2. my @data = <FH>;
  3. close(FH);

I used the above snippet and the following error came up.

Error loading library ./library/agora.setup.db:

No such file or directory at ./library/agora.setup.db line 339. Compilation failed in require at (eval 7) line 1.

Please fix the error and try again.
May 10 '07 #3
KevinADC
4,059 Expert 2GB
I don't know where the "error loading library" is coming from, but the the next error appears as though the path to the file or the filename is not correct. Make sure to use the full path to the file you want to open. Make sure the spelling is correct and the case is correct if using a case sensitive operating system.
May 10 '07 #4
KevinADC
4,059 Expert 2GB
Is it a text file you are wanting to get the data from into your perl script? If not, my suggestion will not work.
May 10 '07 #5
cassbiz
202 100+
Is it a text file you are wanting to get the data from into your perl script? If not, my suggestion will not work.
Yes it is a txt file. I would insert it into the actual script but the end user needs to alter just the one line and honestly don't trust them with the rest of it.

LOL
May 16 '07 #6
KevinADC
4,059 Expert 2GB
OK, but I really don't understand what you are trying to do so I have no further suggestions unless you can clarify your situation in more detail.
May 16 '07 #7
cassbiz
202 100+
OK, but I really don't understand what you are trying to do so I have no further suggestions unless you can clarify your situation in more detail.

OK I will try,


the current code is:

Expand|Select|Wrap|Line Numbers
  1. blah blah blah
  2.  
  3. ### THE LINE BELOW I WANT TO INCLUDE AS A SEPARATE FILE
  4. ### with the script reading the following line into it.
  5.  
  6. @sc_discount_logic = ("1005||||5%", "1500||||5.00");
  7.  
  8.  
  9. blah blah blah
  10.  
Currently the external file I have is called coupon.txt:
Expand|Select|Wrap|Line Numbers
  1. ### Change below
  2.  
  3. @sc_discount_logic = ("1005||||5%", "1500||||5.00");
  4.  
  5.  

I have tried the open() function that you wrote earlier, had all files in the
same directory.

when I used the snippet you provided, the script erred. Put it back to the original and it runs fine.
May 17 '07 #8
KevinADC
4,059 Expert 2GB
Then what you really want is a module, not a text file. Either that or put just the data part in the file, not the @array = (blah blah blah) stuff.

coupon.txt:

1005||||5%
1500||||5.00


in your perl scipt:

Expand|Select|Wrap|Line Numbers
  1. open(FH,"coupon.txt") or die "$!";
  2. my @array = <FH>;
  3. close(FH);
  4. chomp(@array);
  5.  
now @array will be populated with the lines from coupon.txt.
May 18 '07 #9

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

Similar topics

14
by: Richard Speiss | last post by:
I am trying to display a random background image for a webpage. I found this code to do it <% 'Defines the number of background images you have Const NUMBER_OF_IMAGES = 2 'Initiates the...
4
by: Erohsik | last post by:
I am using external tables to load data from the data file. But the log files are getting created in the datafile's directory (because of CREATE OR REPLACE DIRECTORY ...) But I want those log...
9
by: Charley Kyd | last post by:
I'm a newbie who needs advice about how to use external files of JavaScript code. I spent an hour this afternoon browsing through JavaScript books at the local book store. In about 15 different...
10
by: Pasquale | last post by:
hello wverybody... i've got a terrible matter with JS my browsers (either IE and NN) load the external scripts uncorrectly...they load the files from the half part of them and not from the...
2
by: Sara | last post by:
Hi - I've been reading the posts for a solution to my query, and realize that I should ask an "approch" question as well. We receive our production data from a third party, so my uers import...
4
by: Adam Smith | last post by:
Hello, How can I call or trigger an external javascript twice in a form? I have <script language="JavaScript" src="country_state.js" name="Country_State"> <script type="text/javascript"...
5
by: althafexcel | last post by:
hi everyone Im trying to include an external js in my aspx page under the head tag, it doesn't load or it displays an object expected error whenver the function from the .js is called. Actually...
2
by: Heikki Toivonen | last post by:
We have successfully used a script to run external programs for several years. Now we upgraded our Python to 2.5, and are hitting a mysterious error. The expected output from the sample script...
4
by: shelley_2000 | last post by:
What is the best approach to collect and load Employee Resume Data from External Employees who may not have Microsoft access? If is likely they will have Microsoft Word, but not Microsoft Access. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.