Perl Newbie - Printing value from array -
I'm new to Perl, I'm trying to capture the string outside some JSON output. My code works below, but it seems that a smart way to do this is true, "reportMetadata": {"reportFormat": "tabulated", "detailColumns": JSON here
{Code> $ var1 = '{"hasDetailRows" is a sample of ["SUBJECT", "COMMENT_CREATED_DATE", "CASE_COMMENT_CREATED_BY"], "reportBooleanFilter": Null, "reportFilters": [{"Column": "CASE_COMMENT_CREATED_BY" "Operator": "value": "value": "user name"}], "set": ["rOWCOUNT"], "groupingsDown": [], "groupingsAcross": [], "developerName": "My_Comments", "reportType": {"type": "CaseList", "label": "case"} "": "" "{" "" "": "" "{" "" ":" value " : "Id", "label": "description"}, {"Value": "2014-02-17T22: 01: 17Z", "label": "2/17/2014 4:01 pm"}, {"value": "user id", "label": "user ! / Usr / bin / perl warnings; use strict; WWW :: mechanize; Use WWW :: Salesforce; Use data: Dumper; Use JSON -support_by_pp; Use 5.010; Usage Date: Pars; My $ mech = WWW :: Instrumentation- & gt; new (); $ Mech- & gt; Agent ('Mozilla / 5.0'); To get #Session ID, first authenticate with SOAP interface: My $ sforce = eval {WWW :: Salesforce- & gt; Login (username = & gt; 'REDACTED', password = & gt; 'REDACTED'); }; Died "could not enter SFDC: $ @" if $ @; # Get session ID: My $ hdr = $ sforce-> Get_session_header (); My $ sid = $ {$ hdr- & gt; {_ Value} - & gt; [0]} - & gt; {_ Value} - & gt; [0]; # Our requests $ mech- & gt; Add_header ("authorization" = & gt; "OAuth $ sid"); $ Mech- & gt; Ad_header ("x-preetyprint" => 1 '); $ Mech- & gt; Receive ("Some URLs that return to JSON"); My $ content = $ mech- & gt; material; My $ json = new JSON; My $ json_text = $ json- & gt; Allow_nonref- & gt; Utf8- & gt; Relaxed-> Escape_slash-> Loose-> Allow_singlequote- & gt; Allow_barekey-> Decode ($ content);
I currently have the value that holds the value that I want from $ content. I need all the first result, which is why I was killing the loop after the first part I am Every time I tried to do it without a loop, I get "no cheerful reference". So I just need to know that the value of $ timestamp is the correct syntax for printing. <$> {$ Json_text- & gt; {Factmark} - & gt; {'T! T'} - & gt; {Lines}} {My $ Now = Time (); My $ timestamp = strobetime ($ field-> gt; {dataCells} [1] - & gt; {'label'}); My $ diff = int (($ now - $ timestamp) / 60); My $ current = gets (); Print $ current "\ t"; "Time after last activity": $ difference "minutes!" ; last; } Sub Milaning Time {My ($ sec, $ min, $ hour, $ month, $ mone, $ year, $ wday, $ yday, $ isdst) = local time (time); My $ nice_timestamp = sprintf ("% 04d-% 02d-% 02d% 02d:% 02d:% 02d", $ year + 1900, $ mon + 1, $ mday, $ hour, $ min, $ sec); Return $ nice_timestamp; }
I do not know what your non-loop version is like, but it's working ($ Json_text- & gt; {Factmark} {'T! T'} {Rows} [0] {Data Sessions} [1] {Label:
My $ Timestamp = Stretch Time });
Currently, you can
$ json_text- & gt; {FactMap} {'T! T '} are looping on the elements of the array referenced by {rows}
... and stop at the first entry
$ json_text-> gt; ; {Factmap} {'t! T '} {rows}} [0]
... and dereferencing it to get
$ json_text- & gt; {Factmap} {'t! T '} {rows} [0] {dataCells} [1] {label}
Comments
Post a Comment