Solved

Assigning a string with a ' in it

Posted on 2011-03-25
14
220 Views
Last Modified: 2012-05-11
How can I assign the following data to $string?  It has a ' in the line so I'm having trouble with it.


Target Name: s02asqlp_MSSQL_DB Target Type: Microsoft SQL Server Host Name: s02asqlp.na.ipaper.com Metric Name: type Key Name: Type of Record;Record Number Key Value: Application;3653034 TimeStamp: Mar 25, 2011 10:10:28 AM CDT Severity: Warning Message: Event generated for source (SQLSERVERAGENT) at time Fri, Mar 25, 2011, 10:08:00 AM. Details - User[]:Category[Job Engine]:Description[SQL Server Scheduled Job 'Log Shipping Alert Job - Restore' (0x5147AB34F8A62A4F8CF18821274B107E) - Status: Failed - Invoked on: 2011-03-25 10:08:00 - Message: The job failed. The Job was invoked by Schedule 494 (Log Shipping Alert Job - Restore). The last step to run was step 1 (Log Shipping Alert Job - Restore). ] Rule Name: DSQLDBSL_PROD_102608472 Rule Owner: DSYSMAN Metric Value: Warning : 9F351B69978130ADE0440021283CA56A : 0 : 0 : 1 : 9F351B69978130ADE0440021283CA56A
0
Comment
Question by:David Aldridge
  • 6
  • 6
  • 2
14 Comments
 
LVL 26

Expert Comment

by:wilcoxon
ID: 35216187
$string = <<"END_STRING";
Target Name: s02asqlp_MSSQL_DB Target Type: Microsoft SQL Server Host Name: s02asqlp.na.ipaper.com Metric Name: type Key Name: Type of Record;Record Number Key Value: Application;3653034 TimeStamp: Mar 25, 2011 10:10:28 AM CDT Severity: Warning Message: Event generated for source (SQLSERVERAGENT) at time Fri, Mar 25, 2011, 10:08:00 AM. Details - User[]:Category[Job Engine]:Description[SQL Server Scheduled Job 'Log Shipping Alert Job - Restore' (0x5147AB34F8A62A4F8CF18821274B107E) - Status: Failed - Invoked on: 2011-03-25 10:08:00 - Message: The job failed. The Job was invoked by Schedule 494 (Log Shipping Alert Job - Restore). The last step to run was step 1 (Log Shipping Alert Job - Restore). ] Rule Name: DSQLDBSL_PROD_102608472 Rule Owner: DSYSMAN Metric Value: Warning : 9F351B69978130ADE0440021283CA56A : 0 : 0 : 1 : 9F351B69978130ADE0440021283CA56A
END_STRING
0
 
LVL 26

Accepted Solution

by:
wilcoxon earned 400 total points
ID: 35216200
Or if you want to make sure nothing in the data gets interpolated, you can use

$string = <<'END_STRING';

as the opening line.
0
 
LVL 4

Assisted Solution

by:dagesi
dagesi earned 100 total points
ID: 35216259
Considering the size, wilcoxon's option is probably best.

For smaller amounts, use q, where everything contained within the parens becomes part of the string.

$bar = q(everything here is included, including the 'quotes');
0
 
LVL 1

Author Comment

by:David Aldridge
ID: 35216468
Ok, the $string<<'END_STRING'; option seems to be working, but what if I want to get the data from @ARGV?  Sorry.. I should have added that to the original question.  That data is passed to the script.
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 35216611
I don't follow.  Is the data in $ARGV[0] or is it one line per @ARGV element or something else?

If the data is already in @ARGV, you can just assign it to string:

$string = shift; # or $string = $ARGV[0];
#or
$string = join "\n", @ARGV;

If you are saying the issue is a shell issue then the easiest thing to do is to put the data in a file and call your script as:

script.pl < file_containing_data

and the script could have:

$string = join '', <>;
0
 
LVL 1

Author Comment

by:David Aldridge
ID: 35216873
Currently, I'm getting the data in like this:

my $string = join(' ', @ARGV) or die;

It gets assigned, but it has the extra ' in it so when I try to use it to remove unwanted data like:

if ( $string =~ /Warning \: .* \: 0 \: 0 \: 1 \: .*/ ) {      
      $string =~ s/Warning \: .* \: 0 \: 0 \: 1 \: .*//;
}

It breaks because of the extra '.
0
 
LVL 1

Author Comment

by:David Aldridge
ID: 35216900
Sorry, I guess I could have been a bit more clear in the beginning.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 26

Expert Comment

by:wilcoxon
ID: 35217178
What makes you think it is breaking because of the extra ' in the data?

What are you trying to do with your code?  It is doing exactly what you are telling it (which may not be what you actually want).
0
 
LVL 1

Author Comment

by:David Aldridge
ID: 35217868
The "Warning" section which is at the end, isn't included in the substitution because of the extra ' in the string.
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 35217918
How so?  The final warning message is removed?

See blocks below...
### text after running your code
Target Name: s02asqlp_MSSQL_DB Target Type: Microsoft SQL Server Host Name: s02asqlp.na.ipaper.com Metric Name: type Key Name: Type of Record;Record Number Key Value: Application;3653034 TimeStamp: Mar 25, 2011 10:10:28 AM CDT Severity: Warning Message: Event generated for source (SQLSERVERAGENT) at time Fri, Mar 25, 2011, 10:08:00 AM. Details - User[]:Category[Job Engine]:Description[SQL Server Scheduled Job 'Log Shipping Alert Job - Restore' (0x5147AB34F8A62A4F8CF18821274B107E) - Status: Failed - Invoked on: 2011-03-25 10:08:00 - Message: The job failed. The Job was invoked by Schedule 494 (Log Shipping Alert Job - Restore). The last step to run was step 1 (Log Shipping Alert Job - Restore). ] Rule Name: DSQLDBSL_PROD_102608472 Rule Owner: DSYSMAN Metric Value:

Open in new window

### original text
Target Name: s02asqlp_MSSQL_DB Target Type: Microsoft SQL Server Host Name: s02asqlp.na.ipaper.com Metric Name: type Key Name: Type of Record;Record Number Key Value: Application;3653034 TimeStamp: Mar 25, 2011 10:10:28 AM CDT Severity: Warning Message: Event generated for source (SQLSERVERAGENT) at time Fri, Mar 25, 2011, 10:08:00 AM. Details - User[]:Category[Job Engine]:Description[SQL Server Scheduled Job 'Log Shipping Alert Job - Restore' (0x5147AB34F8A62A4F8CF18821274B107E) - Status: Failed - Invoked on: 2011-03-25 10:08:00 - Message: The job failed. The Job was invoked by Schedule 494 (Log Shipping Alert Job - Restore). The last step to run was step 1 (Log Shipping Alert Job - Restore). ] Rule Name: DSQLDBSL_PROD_102608472 Rule Owner: DSYSMAN Metric Value: Warning : 9F351B69978130ADE0440021283CA56A : 0 : 0 : 1 : 9F351B69978130ADE0440021283CA56A

Open in new window

0
 
LVL 1

Author Comment

by:David Aldridge
ID: 35217977
I get "Bareword found where operator expected, near "Log"
Syntax error, near "Log Shipping "
Bad name after Restore'.
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 35218013
That error is not coming from the code you posted (at least I'm not getting it).  Can you post your whole script?  And exactly how is the script being called?
0
 
LVL 1

Author Comment

by:David Aldridge
ID: 35218432
I should have known someone changed something.  The application sending the trap was modified.  Thank you for your help and the code you originally gave me will come to great use!

Sorry for taking so much of your time when I should have done a little more snooping around.
0
 
LVL 4

Expert Comment

by:dagesi
ID: 35218579
thx for the assist...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now